Convert nested for-loops into single LINQ statement

后端 未结 5 1120
一生所求
一生所求 2021-02-08 03:23

can someone please help me turn this nested structure into a single LINQ statement?

        EventLog[] logs = EventLog.GetEventLogs();
        for (int i = 0; i          


        
5条回答
  •  灰色年华
    2021-02-08 03:54

    Have a look:

    List result = new List();
    
    GetEventLogs().Where(x => x.LogDisplayName.Equals("AAA")).ToList().ForEach(delegate(Log en)
    {
        en.Entries.Where(y => y.Source.Equals("BBB", StringComparison.InvariantCultureIgnoreCase)).ToList().ForEach(delegate(Entries ent)
        {
            result.Add(ent);
        });
    });
    

提交回复
热议问题