3
-bgm-
8y

!rant

I just found out that if you have a list of lists in C#, you can use a LINQ statement and specify indices inside the lambda instead of nested ForEaches.

This code is giving me the vapors

Comments
  • 0
    May I see an example?
  • 1
    @shittywebdev if you wanted to check the first item in the inner list against a generic type, for example, you could do something like:

    List<object> innerListType = listOfLists.Find(x => x[0].GetType() == typeof(T)

    I didn't know you could put indices in the lambda before today
  • 2
    @-bgm- but that's not a LINQ statement at all.
  • 0
    @benhongh Find is an extension method from LINQ though
  • 0
  • 0
    @benhongh I thought so, I do know for sure about min, max, etc methods though. But either way you're right in that it's not a linq statement.
  • 1
    @LucaScorpion iirc find is a method on List<T>. Linq equivalents are Single, SingleOrDefault, First, FirstOrDefaut, Where.

    Disclaimer: I haven't coded in C# for a while now I might be wrong.
Add Comment