小编the*_*nth的帖子

Linq其中值在Array中

IEnumerable<string> periods = new string[] {"ABC", "JKD", "223A"};

var someData = from p in returns  
               from d in p.ReturnDet  
               where p.Year > 2009 
               where d.Period <is in periods array> 
Run Code Online (Sandbox Code Playgroud)

如何选择句点数组中包含d.periods的值?

c# linq

23
推荐指数
1
解决办法
3万
查看次数

当我尝试获取类型的计数时,为什么LINQ查询会抛出异常

public readonly IEnumerable<string> PeriodToSelect = new string[] { "MONTH" };  

var dataCollection = from p in somedata    
from h in p.somemoredate    
where h.Year > (DateTime.Now.Year - 2)    
where PeriodToSelect.Contains(h.TimePeriod)  
select new  
{  
    p.Currency, 
    h.Year.Month, h.Value                                                    
}; 
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我为什么在下面的代码行中抛出异常?

int count = dataCollection.Count();  
Run Code Online (Sandbox Code Playgroud)

这是例外:

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ...
Run Code Online (Sandbox Code Playgroud)

c# linq linq-to-objects exception-handling

15
推荐指数
2
解决办法
4万
查看次数

标签 统计

c# ×2

linq ×2

exception-handling ×1

linq-to-objects ×1