Tuesday, May 27, 2008

What is LinQ?

LinQ stands for "Language Integrated Query". It extends C# and visual basic syntax with the new LinQ syntax to provide more capabilities in your code.

It's an interesting feature in C# 3.0. I'll hit an example for LinQ. consider the following class:

   1: class Student

   2:  {

   3:      int id;


   4:  

   5:      public int Id

   6:      {

   7:          get { return id; }

   8:          set { id = value; }

   9:      }

  10:      string studentName;

  11:  

  12:      public string StudentName

  13:      {

  14:          get { return studentName; }

  15:          set { studentName = value; }

  16:      }

  17:  

  18:  }



List<Student> studentList = GetStudentList();


now you need to find all student with name John:


   1: var studentQurey = from student in students

   2:                    where student.StudentName == "John"

   3:                    select student;

   4: studentQurey.ToList();


that was a so simple example for LinQ. You can use LinQ to SQL to search in a database in your application and a lot of feature included in LinQ.