I need to add arraylist of items in linq.Below is my sample code.
string[] _str = ("1.21,2.02,3.14,4.951,5.156").ToString().Split(',');
double Sum = 0.0;
for (int i = 0; i < _str.Length; i++)
{
if (_str[i].ToString() != ",")
Sum = Sum + Convert.ToDouble(_str[i]);
}
The above code i have done in for loop to get the sum of all items in the array list. I need to convert the same operation in linq.Please anyone help me solve this since i’m new to linq.
Thanks in advance.
But if you are doing this for sake of learning linq
If you are sure that the string will always contain valid numeric strings. Then you can just use double.Parse(x).