Convert nested for-loops into single LINQ statement

后端 未结 5 1118
一生所求
一生所求 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:56

    Try this:

     EventLog[] logs = EventLog.GetEventLogs(); 
     remoteAccessLogs.AddRange(
       logs.Where(l => l.LogDisplayName.Equals("AAA"))
         .Select(l => l.Entries)
         .Where(le => le.Source.Equals("BBB"));
    

    However if performance is an issue I would expect this has at least the same algorithmic complexity, if not worse, as we are iterating over the list again to AddRange.

提交回复
热议问题