-1

Is there an easy way to directly convert my list of string into double data type and get the average value.

Here is my current list result:

["6.3000e-009", "7.3319e-009", "7.8303e-009"]

expected result:

7.15E-09

Any suggestion/Comments TIA.

Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
Syntax Rommel
  • 932
  • 2
  • 16
  • 40

2 Answers2

2

You can use Linq to get the average:

var avg = input.Select(double.Parse).Average();
Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
1

you can use Linq to objects to do this quite easily

something like..(untested)

var result = yourArray.Select( s => Double.Parse(s) ).Average();
Tim Jarvis
  • 18,465
  • 9
  • 55
  • 92