Created
October 11, 2021 17:25
-
-
Save asvignesh/a37854da8e9e5ffbfe9775853b2f7bfb to your computer and use it in GitHub Desktop.
C# LIST
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
Creating 3 Students and add to List | |
Print all 3 Students | |
1, Ramya, CSE | |
2, Devi, CSE | |
3, Priya, IT | |
Find department of a student name Ramya | |
CSE | |
Remove 2nd student from list | |
Print all 2 Students | |
1, Ramya, CSE | |
2, Devi, CSE |
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 ListSample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Creating 3 Students and add to List"); | |
List<StudentDto> students = new List<StudentDto>(); | |
StudentDto student1 = new StudentDto | |
{ | |
id = 1, | |
name = "Ramya", | |
department = "CSE" | |
}; | |
students.Add(student1); | |
StudentDto student2 = new StudentDto | |
{ | |
id = 2, | |
name = "Devi", | |
department = "CSE" | |
}; | |
students.Add(student2); | |
StudentDto student3 = new StudentDto | |
{ | |
id = 3, | |
name = "Priya", | |
department = "IT" | |
}; | |
students.Add(student3); | |
Console.WriteLine("Print all 3 Students"); | |
foreach (var student in students) | |
Console.WriteLine(student.id + ", " + student.name + ", " + student.department); | |
Console.WriteLine("Find department of a student name Ramya"); | |
var result = from s in students | |
where s.name == "Ramya" | |
select s.department; | |
Console.WriteLine(result.First()); | |
Console.WriteLine("Remove 2nd student from list"); | |
students.RemoveAt(2); | |
Console.WriteLine("Print all 2 Students"); | |
foreach (var student in students) | |
Console.WriteLine(student.id + ", " + student.name + ", " + student.department); | |
} | |
} | |
} |
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; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ListSample | |
{ | |
class StudentDto | |
{ | |
public int id { get; set; } | |
public string name { get; set; } | |
public string department { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment