Home > OS >  Remove list items' property from list in c#
Remove list items' property from list in c#

Time:12-07

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},
]

CodePudding user response:

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();

CodePudding user response:

  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;


      


            



        
  • Related