Practical usage of Generic List<T> as a data source in LINQ.
Step 2 : Used List<T> collection for Demo:
List<string> list=new List<string>();
list.Add("Arun");
list.Add("Bala");
list.Add("Parthiban");
Step 3 : Code Snippet:
using System;
using System.Collections.Generic;
using System.Linq;
namespace SampleTest
{
public partial class LINQSample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ListDataSource();
}
//Practical usage of Generic List<T> as a data source in Linq
private void ListDataSource()
{
List<string> list = new List<string>();
list.Add("Arun");
list.Add("Bala");
list.Add("Parthiban");
//Retrive the list collection in query.
var queryAllCustomers = from name in list
select name;
//Convert the Collection to List<T>.
List<string> outPut = queryAllCustomers.ToList();
//Display results
foreach (string str in outPut)
{
Response.Write(str);
}
}
}
}
Step 4 : Output: