Arun
Arun

Reputation: 1704

Add two split string values in c#

I need to add split string values to get the rounded value.

string Temp1="0.0154275894165039,1.11531066894531,0.294834136962891,";

string[] Temp2=Temp1.Split(',');

How to sum the values coming in "temp2" and assign it to another parameter.

Upvotes: 0

Views: 268

Answers (3)

Anders Marzi Tornblad
Anders Marzi Tornblad

Reputation: 19305

Consider also passing CultureInfo.InvariantCulture to double.Parse. Otherwise your solution will fail on systems running on certain localization settings.

Upvotes: 1

Shai
Shai

Reputation: 25595

Try this:

double dSum = 0;

foreach (string sStr in Temp2)
    dSum += Double.parse(sStr);

Upvotes: 6

SLaks
SLaks

Reputation: 887807

You can use LINQ:

values.Select(double.Parse).Sum()

Upvotes: 5

Related Questions