Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Programs
{
public class Student
{
public string First { get; set; }
public string Last { get; set; }
public int ID { get; set; }
public List
public ContactInfo GetContactInfo(Programs pg, int id)
{
ContactInfo allinfo =
(from ci in pg.contactList
where ci.ID == id
select ci)
.FirstOrDefault();
return allinfo;
}
public override string ToString()
{
return First + "" + Last + " : " + ID;
}
}
public class ContactInfo
{
public int ID { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public override string ToString() { return Email + "," + Phone; }
}
public class ScoreInfo
{
public double Average { get; set; }
public int ID { get; set; }
}
List
{
new Student {First="Tom", Last=".S", ID=1, Marks= new List
new Student {First="Jerry", Last=".M", ID=2, Marks= new List
new Student {First="Bob", Last=".P", ID=3, Marks= new List
new Student {First="Mark", Last=".G", ID=4, Marks= new List
};
List
{
new ContactInfo {ID=111, Email="Tom@abc.com", Phone="9328298765"},
new ContactInfo {ID=112, Email="Jerry123@aaa.com", Phone="9876543201"},
new ContactInfo {ID=113, Email="Bobstar@aaa.com", Phone="9087467653"},
new ContactInfo {ID=114, Email="Markantony@qqq.com", Phone="9870098761"}
};
static void Main(string[] args)
{
Programs pg = new Programs();
IEnumerable
from student in pg.students
where student.ID > 1
select student.Last;
Console.WriteLine("\r\n studentQuery2: select range_variable.Property");
foreach (string s in studentQuery2)
{
Console.WriteLine(s);
}
Console.ReadLine();
}
}
Output:
studentQuery2: select range_variable.Property
.M
.P
.G
More C# Programs: