Enumerable.Concat not working

前端 未结 2 1629
甜味超标
甜味超标 2020-12-20 14:05

Below is the code:

string[] values = Acode.Split(\',\');
IEnumerable tst = null;

foreach (string a in values)
{
    if (tst== null)
        tst          


        
2条回答
  •  青春惊慌失措
    2020-12-20 14:47

    That is because Concat will return a new instance of your enumerable.

    Either use in your else :

    tst = tst.Concat(...)

    Or Change your Enumerable into list from the beginning :

    string[] values = Acode.Split(',');
    List tst= new List;
    
    foreach (string a in values)
    {
        tst.AddRange(entities.Test.Where(g => (g.TCode == Convert.ToInt16(a))));
    }
    
    return tst;
    

提交回复
热议问题