Why is an identifier expected when declaring a delegate?

When we create a delegate in C # to indicate a function with a specific signature (set of parameters), it asks for an identifier for each type.

public delegate void myDelegate(int x, int y);  

if I try to write this prototype declaration as:

public delegate void myDelegate(int, int)

it shows a compile-time error by saying identifier expected.

But for me, when we simply indicate the prototype of the method, why does the compiler need an identifier to distinguish between two methods with different signatures:

public delegate void firstDelegate(int);

and

public delegate void secondDelegate(int, int);

are a sufficient and clear expression of the difference between them. I think so

I think you got me?

+4
source share
1 answer

It can make a difference at the dial peer. For instance:

using System;

class Test
{
    delegate void Foo(int x, int y);

    static void Main()
    {
        Foo foo = (x, y) => Console.WriteLine("x={0}, y={1}", x, y);
        foo(x: 5, y: 10);
        foo(y: 10, x: 5);
    }
}

x=5, y=10 , , . # # 4, VB.NET .

, , . , , , , , , ?

, ? , , .

, .

+8

Source: https://habr.com/ru/post/1535281/


All Articles