Collection Initialize

Collection Initialize is used to initialize multiple object values at once. In general, collection initialize are created by using the “List” collection class and the list collection class is initialized from  “ I enumerable”   Interface.

Example with collection Initializes:-

Name space  CA Sample

{

Class Employee 2

{

Public int age, Emp Id;

Public String ename, address;

}

Class Example 6

{

Static void Main ()

{

List <Employee 2> Emp list  = New list  < Employee 2>  ()

{

New Employee 2 {  emp id = 101 , e name = “R” Add. “hyd”, “Age = 22”}

New Employee 2 {  emp id = 102 , e name = “V” Add. “bglr”, “Age = 24”}

};

For each (var x in emplist)

C.W.L (“X.emp id +”,”+x.ename +”,”+x.add+ “,”+x.age);

Read ();

}

}

}

Working with Query’s in LINQ:-

A LINQ Query that is divided into 3 types:-

  1. From Clause
  2. Where Clause
  3. Select Clause

Inclined to build a profession as ASP.net Developer? Then here is the blog post on, explore ASP.net Training

Syntax of Query in LINQ:-

Syn:-  From Variable in collection Name Where condition Select variable. Select variable   (select clause)

  • When we want with Query in LINQ we need to follow 3 steps

  • preparing a Data Stage.
  • Writing Query.
  • Executing Query.  

 Example to work with a query on Simple list data:-

Name space  CA Sample

{

Class Employee 7

{

Static void Main ()

Step 1 // List <int>  L1 = new list <int>  {1,2,3,4,5,6,7,8,9,10};

Var  R = From  X in L1 where XYZ == 0 Select X;  //step 2

C.W.L   (“Even No in The list are :-”);

For each  (var I in R); //step 3

Write (I + “”);

Read ();

}

}

}

For in-depth understanding click on