Asp.Net

Tuesday, 12 August 2014

LINQ Samples

LINQ1:
int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8 };
           var num = from n in arr
                      where n<=5
                      select n;
            foreach(var x in num)
            {
                Response.Write(x);
            }
LINQ2:

int[] arr1 = { 1, 2, 3, 4, 5, 6, 7, 8 };

            var numberGroups =
            from n1 in arr1
            where n1 % 2 == 0
            select n1;

            foreach (var y in numberGroups)
            {
                Response.Write(y);
            }

No comments:

Post a Comment