Created
January 1, 2023 05:45
-
-
Save syedharoonmca/3ab35af82f303a3d4652b2a70b45110b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace LINQDemo | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
List<Student> studentList = new List<Student>() | |
{ | |
new Student(){ID = 1, Name = "James", Gender = "Male"}, | |
new Student(){ID = 2, Name = "Sara", Gender = "Female"}, | |
new Student(){ID = 3, Name = "Steve", Gender = "Male"}, | |
new Student(){ID = 4, Name = "Pam", Gender = "Female"} | |
}; | |
//Linq Query to Fetch all students with Gender Male | |
IEnumerable<Student> QuerySyntax = from std in studentList | |
where std.Gender == "Male" | |
select std; | |
//Iterate through the collection | |
foreach (var student in QuerySyntax) | |
{ | |
Console.WriteLine( $"ID : {student.ID} Name : {student.Name}"); | |
} | |
Console.ReadKey(); | |
} | |
} | |
public class Student | |
{ | |
public int ID { get; set; } | |
public string Name { get; set; } | |
public string Gender { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment