Monday, April 13, 2009

LINQ TO OBJECTS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace linq
{
public class student
{
public int id { get; set; }
public string name { get; set; }
public string fname { get; set; }
public List<int> scores;
}
class Program
{
static List<student> students = new List<student>
{
new student{id = 1,name = "sumair",fname ="irshad",scores = new List<int>{90,80,70,60}},
new student{id = 2,name = "JIMM",fname = "CARRY",scores = new List<int>{90,30,30,30}},
new student { id = 3 ,name = "ANDREW", fname = "HEJISBERG",scores = new List<int>{90,90,90,90}},
new student { id = 4 ,name = "BILL",fname = "GATES",scores = new List<int>{80,10,10,10}}

};


static void Main(string[] args)
{
var getscorequery = from student in students
where student.scores [0]>=90
select student;

foreach (student s in getscorequery)
{
Console.WriteLine("{0},{1}", s.id, s.name);
}
Console.ReadKey();
}

}
}

OUTPUT:

1, SUMAIR
2, JIMM
3, ANDREW

No comments:

Post a Comment