LINQ: How to declare IEnumerable[AnonymousType]?

后端 未结 6 1921
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 09:34

This is my function:

    private IEnumerable SeachItem(int[] ItemIds)
    {
        using (var reader = File.OpenText(Application.StartupPath + @\"         


        
6条回答
  •  感动是毒
    2021-02-02 10:08

    One thing to remember is that LINQ statements use deferred execution. What that means is that your LINQ statement doesn't actually execute until you either iterate over it in a foreach statement or you call the .ToList() method on myLine.
    For your example try changing:

    return myLine;
    

    To:

    return myLine.ToList();
    

提交回复
热议问题