LINQ: How to declare IEnumerable[AnonymousType]?

后端 未结 6 1842
被撕碎了的回忆
被撕碎了的回忆 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:05

    Return a ValueTuple instead of an anonymous class. Ex (using "named tuples")-

    (Text: line, ItemId: id, Path: m.Groups[2].Value)
    

    https://docs.microsoft.com/en-us/dotnet/csharp/tuples

    Instead of-

    new { Text = line, ItemId = id, Path = m.Groups[2].Value }
    

    The ValueTuple is part of C# version 7 and was originally implemented as a separate NuGet package (System.ValueTuple). Starting with .NET 4.7 it is a built-in type. For .NET Core, versions prior to 2.0 required the NuGet package but it is built-in with version 2.0.

提交回复
热议问题