是否可以重写代码以减少选择次数?(Is possible to rewrite the code so as to reduce the number of selects?)
但是这段代码测试正确我想知道有些东西是不正确的,因为3嵌套的SELECT()。 是否可以用2个嵌套的SELECT()重写代码?
var sums = Enumerable.Range(1, int.Parse(Console.ReadLine())) .Select(x => Console.ReadLine()) .Select(y => y.Split(' ') .Select(int.Parse).Sum());However this code tested correctly I am wondering about there is something is not correct, because 3 nested SELECT(). Is possible to rewrite the code with 2 nested SELECT()?
var sums = Enumerable.Range(1, int.Parse(Console.ReadLine())) .Select(x => Console.ReadLine()) .Select(y => y.Split(' ') .Select(int.Parse).Sum());最满意答案
您可以将ReadLine与Split结合使用:
var sums = Enumerable.Range(1, int.Parse(Console.ReadLine())) .Select(x => Console.ReadLine().Split(' ').Select(int.Parse).Sum());You can combine the ReadLine with the Split:
var sums = Enumerable.Range(1, int.Parse(Console.ReadLine())) .Select(x => Console.ReadLine().Split(' ').Select(int.Parse).Sum());更多推荐
发布评论