Collection Initialize ASP.net

What is Collection Initialize

Collection Initialize are used to initialize multiple object values at once.

In general collection initialize   are created by using “List” collection class and 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 in to 3 types :-

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

Interested in mastering ASP.net Training?Enroll now for FREE demo on 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

  1. preparing Data Stage.

2.Writing Query.

3.Executing Query.

 

 Example to work with 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 indepth understanding click on