This is a C# Program to produce a filtered sequence of elements that contain only one property of each student.
This C# Program Produces a filtered sequence of elements that contain only one property of each Student using Select Clause LINQ.
Here select clause specifies the type of values that will be produced when the query is executed.
Here is source code of the C# Program to Produce a filtered sequence of elements that contain only one property of each Student. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Produce a filtered sequence of elements * That contain only one property of each Student */ 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<int> Marks; 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<Student> students = new List<Student>() { new Student {First="Tom", Last=".S", ID=1, Marks= new List<int>() {97, 92, 81, 60}}, new Student {First="Jerry", Last=".M", ID=2, Marks= new List<int>() {75, 84, 91, 39}}, new Student {First="Bob", Last=".P", ID=3, Marks= new List<int>() {88, 94, 65, 91}}, new Student {First="Mark", Last=".G", ID=4, Marks= new List<int>() {97, 89, 85, 82}}, }; List<ContactInfo> contactList = new List<ContactInfo>() { new ContactInfo {ID=111, Email="[email protected]", Phone="9328298765"}, new ContactInfo {ID=112, Email="[email protected]", Phone="9876543201"}, new ContactInfo {ID=113, Email="[email protected]", Phone="9087467653"}, new ContactInfo {ID=114, Email="[email protected]", Phone="9870098761"} }; static void Main(string[] args) { Programs pg = new Programs(); IEnumerable<String> studentQuery2 = 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(); } }
This C# program is used to produce a filtered sequence of elements that contain only one property of each Student using Select Clause LINQ. Using IEnumerable Interfaces check the condition that the value of student.ID is greater than 1, which supports a simple iteration over a non-generic collection.
Using Students and Contact List we are reading the First Name, Last Name, Marks, ID, Email, Phone values. The select clause specifies the type of values that will be produced when the query is executed. Print the filtered sequence of elements that contain only one property of each student.
studentQuery2: select range_variable.Property .M .P .G
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for C# Internship
- Buy C# Books
- Buy Computer Science Books
- Apply for Computer Science Internship
- Buy MCA Books