James, I'm not an expert at all, this is my idea. I think this can be reduced to 1. Perhaps there is some more code. the entries are still IEnumerable from AnonymousType {int a, int b}.
* Dynamic was a quick way to solve this problem. You must write a structure for it.
int sum_a = 0,sum_b = 0; Func<string[], dynamic> b = (string[] data) => { sum_a += int.Parse(data[0]); sum_b += int.Parse(data[1]); return new {a = int.Parse(data[0]),b = int.Parse(data[0]) }; }; var records = from line in fileLines let data = line.Split(',') let result = b(data) select new { a = (int)result.a, b = (int)result.b }; var average = sum_b != 0 ? sum_a / sum_b : 0;
For other structures, this is simple.
public struct Int_Int //May be a class or interface for mapping { public int a = 0, b = 0; }
Then
int sum_a = 0,sum_b = 0; Func<string[], Int_Int> b = (string[] data) => { sum_a += int.Parse(data[0]); sum_b += int.Parse(data[1]); return new Int_Int() { a = int.Parse(data[0]), b = int.Parse(data[0]) }; }; var records = from line in fileLines let data = line.Split(',') select b(data); var average = sum_b != 0 ? sum_a / sum_b : 0;
Pedro mora
source share