Hi
I want to declare var Result once only. How it can be declared
var Result = (from t2 in context.View_GroupParticipants
select new { t2.StudentID, Name = t2.Name + " - " + t2.MobileNo }).OrderBy(x => x.Name).Distinct().ToList();
Thanks
Naimish MakwanaPosted Apr 10, 2023, 3:35 AM
Hello Ramco,
you can define a named type for the objects returned by the LINQ query:
Thanks
Naimish Makwana
Ramco RamcoPosted Apr 10, 2023, 3:33 AM
Hi Naimish
It gives error Cannot convert from system.collection.generic.list to system.collection.generic.list
Thanks
Jignesh KumarPosted Apr 10, 2023, 3:32 AM
Hello Raco,
You can refer this link,
https://www.c-sharpcorner.com/Forums/how-to-initialize-implicit-variable
Naimish MakwanaPosted Apr 10, 2023, 3:30 AM
Hello Ramco,
To declare the variable
Resultonly once, you can separate the LINQ query from the variable declaration and assign the result of the query to theResultvariable.Thanks
Naimish Makwana
Tuhin PaulPosted Apr 9, 2023, 8:45 PM
To declare the variable Result once only, you can use the var keyword to infer the type of the result of your LINQ query.
The var keyword is used to declare Result, and its type is inferred from the result of the LINQ query. The query is then chained with the OrderBy, Distinct, and ToList methods to sort, filter, and convert the result to a list.
The type of Result will be List, which is the type of the result of the LINQ query.