A
AMDRIT
I am working with ObservableCollection and looking to implement sorting. I
ran across code from Paul Stovell and he has:
In the collection class the derives from ObservableCollection
public void Sort(Comparison<T> comparrison)
In the logic when initializing the collection class
....
_transactions.Sort(
delegate(Transaction lhs, Transaction rhs) {
return lhs.Date.CompareTo(rhs.Date);
});
....
My question is, how to I represent this same logic? I am unclear on how to
create a delegate function on the fly like that.
I assume that first of all, VB has a white space issue and does not allow me
to create a function pointer on the fly.
So here is what I have done:
In the object class<Transaction> that belongs to the collection (Perhaps, I
should place this in the collection wrapper instead)
Public Shared Function CompareTo(ByVal lhs As Transaction, ByVal rhs
As Transaction) As Integer
Return lhs.Date.CompareTo(rhs.Date)
End Function
I then replaced the sort statement with:
pobjTransactions.Sort(AddressOf Transaction.CompareTo)
Am I missing something here, or is this what is required?
Thanks in advance
ran across code from Paul Stovell and he has:
In the collection class the derives from ObservableCollection
public void Sort(Comparison<T> comparrison)
In the logic when initializing the collection class
....
_transactions.Sort(
delegate(Transaction lhs, Transaction rhs) {
return lhs.Date.CompareTo(rhs.Date);
});
....
My question is, how to I represent this same logic? I am unclear on how to
create a delegate function on the fly like that.
I assume that first of all, VB has a white space issue and does not allow me
to create a function pointer on the fly.
So here is what I have done:
In the object class<Transaction> that belongs to the collection (Perhaps, I
should place this in the collection wrapper instead)
Public Shared Function CompareTo(ByVal lhs As Transaction, ByVal rhs
As Transaction) As Integer
Return lhs.Date.CompareTo(rhs.Date)
End Function
I then replaced the sort statement with:
pobjTransactions.Sort(AddressOf Transaction.CompareTo)
Am I missing something here, or is this what is required?
Thanks in advance