TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
357
120.8k
Delegate
Jun 28 2012 4:09 AM
Hi
Given the following:-
public delegate void SomeDelegate(int x);
class Program
{
static void Main(string[] args)
{
SomeDelegate delinstance = new SomeDelegate(SomeMethod);
delinstance.Invoke(3);
Console.ReadLine();
}
public static void SomeMethod(int x)
{
Console.WriteLine("The number is...{0}", x);
}
I am able to assign the Method to the Delegate without having to create a new object like so:
SomeDelegate delinstance = SomeMethod;
Therefore my question is what is the difference if any, apart from a short hand notation?
Ive previously seen code that creates a new object and passes in the method matching the delegate signature as per my 1st example. And other code using the direct assignment ie method to the delegate in the 2nd example...
Regards
Steven
Reply
Answers (
2
)
How to make and rotate an Image in 360 degree in Metro style App
Getting C# to recognize a dll outside of Visual Studio.