Extension method and dynamic object

后端 未结 3 2182
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 04:50

I am going to summarize my problem into the following code snippet.

List list = new List() { 5, 56, 2, 4, 63, 2 };
Console.WriteLine(li         


        
3条回答
  •  执笔经年
    2020-11-22 05:22

    To expand on Stecya's answer... extension methods aren't supported by dynamic typing in the form of extension methods, i.e. called as if they were instance methods. However, this will work:

    dynamic dList = list;
    Console.WriteLine(Enumerable.First(dList));
    

    Of course, that may or may not be useful. If you could give more information about why and how you're trying to use dynamic typing, we may be able to help more.

提交回复
热议问题