Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert List<double[]> to List<T>
    primarykey
    data
    text
    <p>I have a list of doubles <code>List&lt;double[]&gt;</code> which I want to convert to a <code>List&lt;T&gt;</code> where T is a class.</p> <p>The array of double contains 17 values e.g. [1.0, 2.0, 3.0, 4.0, 5.0,.. 17.0 ]. Then I have a class which defines 17 string properties e.g P1, P2, .... , P17</p> <p>So every element of an <code>List&lt;double[]&gt;</code> is a array of doubles and, every element in the array represents a value for the property in the class of type <code>T</code>.</p> <p>Is it possible to map each index of the given array of doubles to a property of class of type T. So I convert a <code>List&lt;double[]&gt;</code> to <code>List&lt;T&gt;</code> where <code>T</code> is <code>class</code>.</p> <p>I know it can be done by manually iterate over the list read each array and then read value from each index of the array and pass it to corresponding property of a class. But it a lot to do when I have many class with 10+ properties.</p> <p><strong>EDIT:</strong> An example of one of the classes is given below</p> <pre><code> /// &lt;summary&gt; /// Defines the properties of a centroid. /// &lt;/summary&gt; public class Centroid { // ReSharper disable InconsistentNaming /// &lt;summary&gt; /// Calls made to contacts /// &lt;/summary&gt; public string CONTACT_CALLS { get; set; } /// &lt;summary&gt; /// Duration of calls made to contacts /// &lt;/summary&gt; public string CONTACT_CALLS_SEC { get; set; } /// &lt;summary&gt; /// Calls made to non contacts /// &lt;/summary&gt; public string UNKNOWN_CALLS { get; set; } /// &lt;summary&gt; /// Duration of calls made to non contacts /// &lt;/summary&gt; public string UNKNOWN_CALLS_SEC { get; set; } /// &lt;summary&gt; /// Number of SMS sent to contacts /// &lt;/summary&gt; public string SMS_OUT_CONTACTS { get; set; } /// &lt;summary&gt; /// Number of SMS sent to non contacts /// &lt;/summary&gt; public string SMS_OUT_UNKNOWN { get; set; } /// &lt;summary&gt; /// Percentage of CPU usaed /// &lt;/summary&gt; public string CPU_USAGE { get; set; } /// &lt;summary&gt; /// Percentage of RAM used /// &lt;/summary&gt; public string RAM_USAGE { get; set; } /// &lt;summary&gt; /// Number of system application /// &lt;/summary&gt; public string SYS_APPS { get; set; } /// &lt;summary&gt; /// Number of user applications /// &lt;/summary&gt; public string USER_APPS { get; set; } /// &lt;summary&gt; /// Number of system services /// &lt;/summary&gt; public string SYS_SERVICES { get; set; } /// &lt;summary&gt; /// Number of user services /// &lt;/summary&gt; public string USER_SERVICES { get; set; } /// &lt;summary&gt; /// Number of bytes sent /// &lt;/summary&gt; public string BYTES_TX { get; set; } /// &lt;summary&gt; /// Number of bytes received /// &lt;/summary&gt; public string BYTES_RX { get; set; } /// &lt;summary&gt; /// Latitute of the location /// &lt;/summary&gt; public string LOC_LAT { get; set; } /// &lt;summary&gt; /// Longitude of the location /// &lt;/summary&gt; public string LOC_LON { get; set; } /// &lt;summary&gt; /// The Time Slice /// &lt;/summary&gt; public string TIME_SLICE { get; set; } // ReSharper restore InconsistentNaming } </code></pre> <p><strong>EDIT2:</strong> Method which creates a list from list, <strong>NOTE</strong> _profiler.FinalCentroid is of type <code>List&lt;double[]&gt;</code></p> <pre><code> private void CreateListOfCentroids() { _centroidsList = new CentroidsList {Centroids = new List&lt;Centroid&gt;()}; foreach (var centroid in _profiler.FinalCentroid.Select(doublese =&gt; 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload