c# - Convert List<double[]> to List<T> -


i have list of doubles list<double[]> want convert list<t> t class.

the array of double contains 17 values e.g. [1.0, 2.0, 3.0, 4.0, 5.0,.. 17.0 ]. have class defines 17 string properties e.g p1, p2, .... , p17

so every element of list<double[]> array of doubles and, every element in array represents value property in class of type t.

is possible map each index of given array of doubles property of class of type t. convert list<double[]> list<t> t class.

i know can done manually iterate on list read each array , read value each index of array , pass corresponding property of class. lot when have many class 10+ properties.

edit: example of 1 of classes given below

    /// <summary> /// defines properties of centroid. /// </summary> public class centroid {     // resharper disable inconsistentnaming     /// <summary>     /// calls made contacts     /// </summary>     public string contact_calls { get; set; }      /// <summary>     /// duration of calls made contacts     /// </summary>     public string contact_calls_sec { get; set; }      /// <summary>     /// calls made non contacts     /// </summary>           public string unknown_calls { get; set; }      /// <summary>     /// duration of calls made non contacts     /// </summary>     public string unknown_calls_sec { get; set; }      /// <summary>     /// number of sms sent contacts     /// </summary>     public string sms_out_contacts { get; set; }      /// <summary>     /// number of sms sent non contacts     /// </summary>     public string sms_out_unknown { get; set; }      /// <summary>     /// percentage of cpu usaed     /// </summary>     public string cpu_usage { get; set; }      /// <summary>     /// percentage of ram used     /// </summary>     public string ram_usage { get; set; }      /// <summary>     /// number of system application     /// </summary>     public string sys_apps { get; set; }      /// <summary>     /// number of user applications     /// </summary>     public string user_apps { get; set; }      /// <summary>     /// number of system services     /// </summary>     public string sys_services { get; set; }      /// <summary>     /// number of user services     /// </summary>     public string user_services { get; set; }      /// <summary>     /// number of bytes sent     /// </summary>     public string bytes_tx { get; set; }      /// <summary>     /// number of bytes received     /// </summary>     public string bytes_rx { get; set; }      /// <summary>     /// latitute of location     /// </summary>     public string loc_lat { get; set; }      /// <summary>     /// longitude of location     /// </summary>     public string loc_lon { get; set; }      /// <summary>     /// time slice     /// </summary>     public string time_slice { get; set; }      // resharper restore inconsistentnaming } 

edit2: method creates list list, note _profiler.finalcentroid of type list<double[]>

    private void createlistofcentroids()     {         _centroidslist = new centroidslist {centroids = new list<centroid>()};          foreach (var centroid in _profiler.finalcentroid.select(doublese => new centroid         {             contact_calls = doublese[0].tostring(cultureinfo.invariantculture),             contact_calls_sec = doublese[1].tostring(cultureinfo.invariantculture),             unknown_calls = doublese[2].tostring(cultureinfo.invariantculture),             unknown_calls_sec = doublese[3].tostring(cultureinfo.invariantculture),             sms_out_contacts = doublese[4].tostring(cultureinfo.invariantculture),             sms_out_unknown = doublese[5].tostring(cultureinfo.invariantculture),             cpu_usage = doublese[6].tostring(cultureinfo.invariantculture),             ram_usage = doublese[7].tostring(cultureinfo.invariantculture),             sys_apps = doublese[8].tostring(cultureinfo.invariantculture),             user_apps = doublese[9].tostring(cultureinfo.invariantculture),             sys_services = doublese[10].tostring(cultureinfo.invariantculture),             user_services = doublese[11].tostring(cultureinfo.invariantculture),             bytes_tx = doublese[12].tostring(cultureinfo.invariantculture),             bytes_rx = doublese[13].tostring(cultureinfo.invariantculture),             loc_lat = doublese[14].tostring(cultureinfo.invariantculture),             loc_lon = doublese[15].tostring(cultureinfo.invariantculture),             time_slice = doublese[16].tostring(cultureinfo.invariantculture)         }))         {             _centroidslist.centroids.add(centroid);         }     }//end method 

to post obvious, why not assign properties in constructor?
going work of creating properties.
assigning values in constructor less keystrokes property.

list<double[]> ld = new list<double[]>(); list<propdouble> lpd = new list<propdouble>(); foreach (double[] da in ld) { lpd.add(new propdouble(da)); }  public class propdouble {     public double p0 { get; set; }     public double p1 { get; set; }     public propdouble(double[] doubles) { p0 = doubles[0]; p1 = doubles[1]; } } 

or

public class propdouble {     private double[] doubles;     public double p0 { { return doubles[0]; } set { doubles[0] = value; } }     public double p1 { { return doubles[1]; } set { doubles[1] = value; } }     public propdouble(double[] doubles) { doubles = doubles; } } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -