Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between these two delegate statements?

Tags:

c#

.net

delegates

I'm looking at delegates for the first time and wondered what the differnce is between these two styles.

OfferList.NextPage += delegate(int page)
{
    OnNextPage(page);
};


void OnNextPage(int page)
{
    ...
}

and

Toolbar.OfferBookmarkRemoved += new OfferBookmarkRemoved(OnOfferBookmarkRemoved);

void OnOfferBookmarkRemoved(int offerId)
{
    ...
}

Thanks in advance.

like image 901
dotnetnoob Avatar asked Dec 26 '22 17:12

dotnetnoob


1 Answers

The first one is an Anonymous Method, and the second is a Name Method.

See also Delegates with Named vs. Anonymous Methods (C# Programming Guide)

like image 137
Adriaan Stander Avatar answered Feb 13 '23 02:02

Adriaan Stander