【发布时间】:2019-12-16 10:40:29
【问题描述】:
动态变量是否有理由不支持扩展方法?有办法规避吗?
这是一个例子:
我没有忘记持有我正在使用的扩展方法的类的 using 指令:
using System.Linq;
这段代码没有问题:
IEnumerable<string> ie = new HashSet<string>() { "test" };
Console.WriteLine(ie.ToList()[0]);
这个抛出异常:
IEnumerable<string> ie = new HashSet<string>() { "test" };
Console.WriteLine(((dynamic)ie).ToList()[0]);
''System.Collections.Generic.HashSet' 不包含'ToList''的定义
【问题讨论】:
标签: c# .net dynamic extension-methods