c# - Simple linq question: using linq to get an array of properties -


Let's say we have a simple class

  public square fu {public string FooName; }  

Now we want to do some simple work on that.

// What to do here? }

If I also knew what the method of calling is, then maybe I can find the rest of Pais.

You want to change a list of your class into an array of wires. The ideal method for this is to select , which runs on each element on the calculator and makes a new calculation based on the type you return.

The name of the lambda expression selection method that gives you name, which is just "select the name for each element".

Then you have to input the output as an array.

  string [] fooNames = listOfFoos.Select (foo = & gt; foo.FooName) .oir (); Or, using other syntax:  
  string [] fooNames = (foo from Foo in the list, select foo.FooName) .ToArray () ;  

Comments