making a list using inner query in Linq in C#

前端 未结 3 1146
没有蜡笔的小新
没有蜡笔的小新 2021-01-28 18:26

I am trying to create a sublist using Linq but don\'t understand the error in this. I don\'t think i am doing wrong but i think others eye will help me to sort this issue.

3条回答
  •  无人及你
    2021-01-28 18:57

    When I tried to compile that code you posted I get the following exception:

    Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'string[]'. An explicit conversion exists (are you missing a cast?)

    Reason is that you are trying to reuse dataList, but the return types of File.ReadAllLines and string.Join methods don't match. This fixes it:

    dataList = (from line in dataList
                       let temp = from data in line.Split(';').ToList()
                                  where line.Split(';').ToList().IndexOf(data) != 0 || line.Split(';').ToList().IndexOf(data) != 1
                                  select data
                       select string.Join(",", temp)).ToArray();
    

    Cheers,

提交回复
热议问题