Language Integrated Query
and the feature is meant to provide a way to get data from a data source. The data source can heavily vary for each use case, but in terms of using it within Unity, we most likely only work with lists or arrays of objects. LINQ requires the data source to inherit from the IEnumerable<T> interface, may that be directly or indirectly (from a class that inherits from it is also valid). This tutorial focuses on working with lists, because they implement this interface and are therefore ready to work with. ToList()
method (we will see an example later). (input-parameters) => expression
Where()
method is part of the System.Linq namespace and accepts a lambda expression that returns a boolean value. In our case, for each number in the list, we want to check if the number divided by two has zero rest. If that is true, the Where()
method returns this number and adds it to the numQuery2, which will then be printed to the console.