How to Remove specific field from List

Pradip Talaviya picture Pradip Talaviya · Aug 3, 2017 · Viewed 9.8k times · Source

Class structure

 public class EmployeeDetails
 {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Exp { get; set; }
 }

List of employee details

Id Name       Exp
-- ---------  --------
1  Bill       2 years
2  John       5 years
3  Doug       1 years

I want to remove one field form list object like Id, like below output

Name       Exp
---------  --------
Bill       2 years
John       5 years
Doug       1 years

anyone have an idea how to do?
share with me
Thank you

Answer

ΦXocę 웃 Пepeúpa ツ picture ΦXocę 웃 Пepeúpa ツ · Aug 3, 2017

You can try:

var listWithoutCol = List.Select(x => new { x.Name , x.Exp}).ToList();

that will return a List with only the information of the fields Name and Exp...