Language Integrated Query (LINQ) is a set of Integrate query capabilities directly into the C# language.
You can use C# to create SQL Server databases, XML documents,
ADO.NET data sets, and any collection of objects that support IEnumerable or
generic IEnumerable
In Linq-to-SQL, if you try to get the first element in a query that has no results, you will The obtained sequence does not contain any elements Error
ToList returns an empty list
class Program{ public static void Main(){ List<string> list = new List<string> { "a" }; IEnumerable<string> ilist = list.Where(x => x == "ABC").ToList(); System.Console.WriteLine(ilist.Count()); foreach (var item in ilist){ System.Console.WriteLine(item); } Console.ReadLine(); } }
0
class Program{ public static void Main(){ List<int> list = new List<int> { 1 }; IEnumerable<int> ilist = list.Where(x => x == 3).ToList(); System.Console.WriteLine(ilist.Count()); foreach (var item in ilist){ System.Console.WriteLine(item); } Console.ReadLine(); } }
0
The above is the detailed content of What does LINQ return when the result is null in C#?. For more information, please follow other related articles on the PHP Chinese website!