473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Looking for VB Equivalent

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<Tcomparrison)

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<Transactionthat 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
Aug 9 '07 #1
3 1619
AMDRIT,

Anonymous delegates do not exist in VB, as far as I know. However, you
can create lambda expressions if you are using .NET 3.5. The form for what
you want would be:

Function(ByVal lha As Transaction, ByVal rhs As Transaction)
lhs.Date.CompareTo(rhs.Date)

As opposed to:

delegate(Transaction lhs, Transaction rhs) { return
lhs.Date.CompareTo(rhs.Date) }

Before .NET 3.5, you have to create a method and use a delegate that
points to that method.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"AMDRIT" <am****@hotmail.comwrote in message
news:OV**************@TK2MSFTNGP03.phx.gbl...
>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<Tcomparrison)

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<Transactionthat 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

Aug 9 '07 #2
On Aug 14, 4:19 pm, "AMDRIT" <amd...@hotmail.comwrote:
Not only did I learn a new term "Anonymous Delegate", but you have given me
a better understanding of the code surrounding it. I appreciate your help.
Just to be picky, I don't believe that "anonymous delegate" is
standard terminology. There's:

1) Anonymous method - what's being talked about here
2) Lambda expression - the C# 3 feature which is like anonymous
methods but better
3) Anonymous function - term for "anonymous method or lambda
expression"

I only bring it up because I've seen the mistaken term "anonymous
delegate" used a few times recently.

Jon

Aug 14 '07 #3
Jon,

"Jon Skeet [C# MVP]" <sk***@pobox.comschrieb:
>Not only did I learn a new term "Anonymous Delegate", but you have given
me
a better understanding of the code surrounding it. I appreciate your
help.

Just to be picky, I don't believe that "anonymous delegate" is
standard terminology. There's:

1) Anonymous method - what's being talked about here
2) Lambda expression - the C# 3 feature which is like anonymous
methods but better
3) Anonymous function - term for "anonymous method or lambda
expression"

I only bring it up because I've seen the mistaken term "anonymous
delegate" used a few times recently.
I agree with the terms you have listed above. Normally I'd use the term
"anonymous method" in this case too and I do not know why I have chosen
another term.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael Herman \(Parallelspace\) | last post by:
http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/shellcc/wiz97/default.asp is a C++ .Net version of the original Wizard97 sample. My question is:...
2
by: Rick D. | last post by:
Hi all, I'm looking for information on running a c# application on a webpage, just like a java-applet. And the second thing i'm looking for is information on how to display 3d graphics with...
6
by: Christoph | last post by:
I was browsing both the Amazon and Barnes & Noble websites looking for some good books but there appears to be *so* many and it's hard to tell which are going to be good or not. I'm looking for...
1
by: Helene Day | last post by:
In VB6, I used to have something like: Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = vbFormControlMenu Then '''' other logic here...etc... Cancel =...
20
by: dimka | last post by:
Hello Here is my situation: I have a char buf; that is used as a buffer for a log output. Normally, I do: rc = snprintf( buf, sizeof(buf), some_format, some_args ); This makes the...
5
by: ichi32 | last post by:
javascript:alert("The true URL is:\t\t" + location.protocol + "//" + location.hostname + "/" + "\nIf this does not match the URL shown in your browser address bar, you are likely to be seeing a web...
12
by: amogan | last post by:
**If interested & qualified, please reply with your resume directly to amogan@google.com** Referrals are always welcome!! Network System Test Engineer - Mountain View This position is...
13
by: Avi | last post by:
Hi, Is there a UNIX C system command that will let me copy a file? I am looking for something similar to "cp" that can be called within a C program. I know of the "link" system call but this...
20
by: ram.rachum | last post by:
Hey, I'm looking for a good Python environment. That is, at least an editor and a debugger, and it should run on Windows. Does anyone have any idea?
12
by: Stewart Berman | last post by:
Where is the equivalent of the Windows.h (and it's includes) for C#?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.