c# - How can I get type double array from List<string>? -
this question has answer here:
- how convert list of strings doubles? 5 answers
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
Post a Comment