What does Method mean?

后端 未结 5 577
北海茫月
北海茫月 2021-01-31 07:57

I\'ve seen this syntax a couple times now, and it\'s beginning to worry me,

For example:

iCalendar iCal = new iCalendar();
Event evt = iCal.Create

        
5条回答
  •  故里飘歌
    2021-01-31 08:43

    It's the way you mention a generic method in C#.

    When you define a generic method you code like this:

    return-type MethodName(parameter-list)
    

    When you call a generic method, the compiler usually infers the type parameter from the arguments specified, like this example:

    Array.ForEach(myArray, Console.WriteLine);
    

    In this example, if "myArray" is a string array, it'll call Array.ForEach and if it's an int array, it'll call Array.ForEach.

    Sometimes, it's impossible for the compiler to infer the type from the parameters (just like your example, where there are no parameters at all). In these cases, you have to specify them manually like that.

提交回复
热议问题