Using LINQ With Student Array Collection c#



I will teach you with one example of Array and another of List collection. If you are a beginner at LINQ, let me teach you the basic query format for writing queries for LINQ.

using System;
using System.Linq;

namespace CSharpLINQ
{
    class SimpleQuery
    {
		static void Main( )
		{
			var students = new[] // Array of objects of an anonymous type
			{
				new { LName="Mishra", FName="Kuldeep", Age=31 },
				new { LName="Sharma", FName="Ramesh", Age=20 },
				new { LName="Verma", FName="Manoj", Age=21 }
			};

			var query = from student in students select student;
			
			foreach (var q in query)
				Console.WriteLine("Name: {0} {1}, Age: {2}", q.FName, q.LName, q.Age);
		}
    }
}

0 Comment's

Comment Form