Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,011 questions

51,958 answers

573 users

How to use LINQ select query on a list of objects in C#

1 Answer

0 votes
using System;
using System.Linq;
using System.Collections.Generic;

namespace LinqSelect
{
   class Program
   {
     static void Main(string[] args)
     {
        List<Student> studentObj = new List<Student>()
        {
          new Student() { StudentId = 1, Name = "Artemis", Marks = 81 },
          new Student() { StudentId = 2, Name = "Arthur", Marks = 92 },
          new Student() { StudentId = 3, Name = "Emmett", Marks = 78 },
          new Student() { StudentId = 4, Name = "Milo", Marks = 95 },
          new Student() { StudentId = 5, Name = "Amelia", Marks = 86 },
          new Student() { StudentId = 6, Name = "Felicity", Marks = 80 },
          new Student() { StudentId = 7, Name = "Echo", Marks = 98 }
        };
        
        var result = from s in studentObj
                     select new {SName =s.Name,SID = s.StudentId,SMarks = s.Marks };
        
        foreach (var item in result) {
           Console.WriteLine("The StudentName is {0} ID is {1} Marks is {2}", item.SName, item.SID, item.SMarks);
        }
     }
   }
   class Student
   {
      public int StudentId { get; set; }
      public string Name { get; set; }
      public int Marks { get; set; }
   }
} 


/*
run:

The StudentName is Artemis ID is 1 Marks is 81
The StudentName is Arthur ID is 2 Marks is 92
The StudentName is Emmett ID is 3 Marks is 78
The StudentName is Milo ID is 4 Marks is 95
The StudentName is Amelia ID is 5 Marks is 86
The StudentName is Felicity ID is 6 Marks is 80
The StudentName is Echo ID is 7 Marks is 98

*/

 



answered Dec 14, 2025 by avibootz
...