简体   繁体   中英

Remove list items' property from list in c#

I have a list like this, I am creating a csv file with below data and I want to exclude some columns, the properties are column names

[
 {name: john, age: 25},
 {name: mark, age: 30},
]

I want to remove the age property from the list items without any condition just remove the property, so my new list should look like below list and it will be excluded in the csv file

[
 {name: john},
 {name: mark},
]

This may help you:

  List<Employee> listEmployee= new List<Employee>([
     {name: john, age: 25},
     {name: mark, age: 30},
    ])
    var reduceAgeFromList= listEmployee.Select(e => new {e.name}).ToList();
  using linq; // namespace     

  1)  List<details> list= new List<details>()

      var name = list.Where(a => a.name).ToList();  // fetch the data of 
       particular property


  2) var name = from c in list
                 where c.name
                 select c;


      


            



        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM