473,406 Members | 2,894 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,406 software developers and data experts.

events vs. delegates

Why do I have to create new objects implementing IComparer when we can use
delegates?

class Test
{

int CompareStuff(int a, int b)
{
return a-b;
}

void Foo()
{
// in .NET framework 2.0 we could simply write
//Array.Sort(CompareStuff);
// since delegates are implicitly created
Array.Sort(myArray, new ComparerDelegate(CompareStuff));
}

}
Nov 22 '05 #1
2 1881
Sorry for the stupid headline. It should have been interfaces vs. delegates
:)

"cody" <de********@gmx.de> schrieb im Newsbeitrag
news:uT**************@TK2MSFTNGP15.phx.gbl...
Why do I have to create new objects implementing IComparer when we can use
delegates?

class Test
{

int CompareStuff(int a, int b)
{
return a-b;
}

void Foo()
{
// in .NET framework 2.0 we could simply write
//Array.Sort(CompareStuff);
// since delegates are implicitly created
Array.Sort(myArray, new ComparerDelegate(CompareStuff));
}

}

Nov 22 '05 #2
Crap, forget my whole post. I tried it and it already worked that way in VS
2005.
I really should go to bed now :)
The question now is: Why doesn't intellisense show me the overload which
takes Comparison<T> as parameter?

"cody" <de********@gmx.de> schrieb im Newsbeitrag
news:uT**************@TK2MSFTNGP15.phx.gbl...
Why do I have to create new objects implementing IComparer when we can use
delegates?

class Test
{

int CompareStuff(int a, int b)
{
return a-b;
}

void Foo()
{
// in .NET framework 2.0 we could simply write
//Array.Sort(CompareStuff);
// since delegates are implicitly created
Array.Sort(myArray, new ComparerDelegate(CompareStuff));
}

}

Nov 22 '05 #3

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

Similar topics

4
by: Marty McDonald | last post by:
It is still unclear to me why we would use events when delegates seem to do just fine. People say that events make it so the publisher doesn't need to know about the listeners. What does that...
7
by: Rakesh Rajan | last post by:
Hi, I find that when i define a delegate, it gets derived from MulticastDelegate, which provides all funtionality that events would provide (like registering new handlers etc.). Then, apart from...
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
3
by: Chris | last post by:
Hi, what is the difference between using events and delegates (apart from the syntax) ? have a look at following (working) programs please (you can just copy/paste and build it) : First...
11
by: Nicky Smith | last post by:
Hello, I'm studying a book on VB.net Win apps, and I'm reading a section on events and delegates and raising events. Is it just me, or is this not just subs dressed up as something else? I...
4
by: Tim | last post by:
There are a set of clients who need to be notified of certain events. I have used events and delegates (publisher-Subscriber model) for the notification mechanism. All the clients register with...
30
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment...
2
by: kristian.freed | last post by:
Hi, I currently work in a project written fully in C# where we make extensive use of delegates and events. We have a model where a "state", an object holding data but not much code but which...
5
by: raylopez99 | last post by:
I understand delegates (static and non-static) and I agree they are very useful, and that the "Forms" used in the Windows .NET API could not work without them. That said, I'm curious as to how...
7
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.