c# - How can I get type double array from List<string>? -


this question has answer here:

var array1 = (from ir in pmec.interestrateset               select new list<string> { ir.tenor.tostring() }).tolist();  var array2 = (from ir in pmec.interestrateset               select new list<string> { ir.rate.tostring() }).tolist();  array1.addrange(array2);  var array = array1.toarray(); 

for example, array1 has 6 numbers, array2 has 6 numbers, after combined, array has 12 numbers.

then should in order array of type double?

if tenor , rate double properties should not convert them string.

list<double> tenorlist = pmec.interestrateset     .select(irs => irs.tenor)      .tolist(); list<double> ratelist = pmec.interestrateset     .select(irs => irs.rate)      .tolist(); list<double> tenorratelist = tenorlist.concat(ratelist).tolist(); // or... tenorlist.addrange(ratelist); // modifies first list 

but seems pointless, 12 doubles in sample if have 6 objects in interestrateset. better select both properties @ once:

var tenorratelist = pmec.interestrateset     .select(irs => new { tenor = irs.tenor, rate =irs.rate} )      .tolist(); // list of anonymous type  

in general, if have string , want convert double use double.parse or double.tryparse.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -