c# – 匿名类型列表?
发布时间:2020-12-15 18:25:01 所属栏目:百科 来源:网络整理
导读:我需要创建一对/三元组的东西并存储在某个地方.我该怎么做? 我试过了: for (int i = 0; i 100; i++){ var item=new { a=i,b="lala",c=4.5m}; //anonymous type} 但后来我想:列出 what? 我可以使用动态,但我想要Intellisense. (我也可以使用Tuple int,str
我需要创建一对/三元组的东西并存储在某个地方.我该怎么做?
我试过了: for (int i = 0; i < 100; i++) { var item=new { a=i,b="lala",c=4.5m}; //anonymous type } 但后来我想:列出< what>? 我可以使用动态,但我想要Intellisense. (我也可以使用Tuple< int,string,decimal>但是如果我已经拥有了我需要的东西(= new {a = i,b =“lala”,c = 4.5m};),我为什么要使用其他类型(元组)?) 这有什么解决方案吗? 解决方法
您可以使用类型推断
var items = Enumerable.Range(0,100) .Select(i => new { a=i,c=4.5m }) .ToList(); // not necessary (you can use IEnumerable) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |