Skip to content

Instantly share code, notes, and snippets.

@syedharoonmca
Created January 1, 2023 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syedharoonmca/18d7feff797b7cb102cc059f5d0d7c8a to your computer and use it in GitHub Desktop.
Save syedharoonmca/18d7feff797b7cb102cc059f5d0d7c8a to your computer and use it in GitHub Desktop.
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