C#에서 동일한 기본 작업을 수행 할 수 있습니다.
Tuple<double[][], string[]> GetElections()
{
var file = @"C:\Users\Deines\Documents\Election2008.txt";
var fileAsLines = File.ReadLines(file).Select(line => line.Split(','));
var dataset = fileAsLines.Select(line => new[]
{
Convert.ToDouble(line[1]),
Convert.ToDouble(line[2]),
Convert.ToDouble(line[3])
}).ToArray();
var labels = fileAsLines.Select(line => line[4]).ToArray();
return Tuple.Create(dataset, labels);
}
즉, C# 개발자는 이런 식으로 이것을 거의 쓰지 않을 것입니다. 결과 (이름 + 값으로)를 보유하고 (즉)를 읽고 (즉)를 읽을 가능성이 더 높습니다.
class ElectionResult
{
public ElecationResult(string label, double x, double y, int amount)
{
this.Label = label;
this.Point = new Point(x,y);
this.Amount = amount;
}
string Label { get; private set; }
Point Location { get; private set; }
int Amount { get; private set; }
}
IList<ElectionResult> GetElectionResults()
{
var file = @"C:\Users\Deines\Documents\Election2008.txt";
var fileAsLines = File.ReadLines(file).Select(line => line.Split(','));
return fileAsLines.Select(line => new ElectionResult(line[4],
Convert.ToDouble(line[1]),
Convert.ToDouble(line[2]),
Convert.ToInt32(line[3]))
.ToList();
}
튜플 결과에서 배열을 추출하는 패턴이 일치하지 않기 때문에 일반적인 C# 개발자에게는 훨씬 더 유용 할 수 있습니다.