Created
January 1, 2023 05:49
-
-
Save syedharoonmca/18d7feff797b7cb102cc059f5d0d7c8a 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 LINQDemo1 | |
{ | |
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 | |
IQueryable<Student> MethodSyntax = studentList.AsQueryable() | |
.Where(std => std.Gender == "Male"); | |
//Iterate through the collection | |
foreach (var student in MethodSyntax) | |
{ | |
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