c# - split list to multiple list on property basis -


i have class below

 public class flight   {     public int companyid { get; set; }     public int number { get; set; }     public int set{get;set;}      public flight(int companyid, int number, int set)     {         this.companyid = companyid;         this.number = number;         this.set=set;     } } 

i have list of type

var flights = new list<flight>             {                 new flight(10, 10000,1),                  new flight(20, 20000,2),                  new flight(30, 30000,3),                 new flight(40, 40000,4),                 new flight(50, 50000,5),             }; 

i want split list 3 lists or object[] on properties each of type int (or type belongs), expected result

        object[] lista = { 10, 20, 30, 40, 40 };         object[] listb = { 1000, 2000, 3000, 4000, 5000 };         object[] listc = { 1, 2, 3, 4, 5 }; 

can achieved through linq?

edit:sorry not mentioning this, list above may have dynamic properties, want check if can dynamically done?

just select properties , convert array:

var lista = flights.select(f => f.companyid).toarray(); var listb = flights.select(f => f.number).toarray(); var listc = flights.select(f => f.set).toarray(); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -