What does Method mean?

后端 未结 5 571
北海茫月
北海茫月 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:21

    It's calling a generic method - so in your case, the method may be declared like this:

    public T Create()
    

    You can specify the type argument in the angle brackets, just as you would for creating an instance of a generic type:

    List list = new List();
    

    Does that help?

    One difference between generic methods and generic types is that the compiler can try to infer the type argument. For instance, if your Create method were instead:

    public T Copy(T original)
    

    you could just call

    Copy(someEvent);
    

    and the compiler would infer that you meant:

    Copy(someEvent);
    

提交回复
热议问题