是否可以重写代码以减少选择次数?(Is possible to rewrite the code so as to reduce the number of selects?)

编程入门 行业动态 更新时间:2024-10-19 17:32:26
是否可以重写代码以减少选择次数?(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());

更多推荐

本文发布于:2023-08-01 11:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1357985.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   次数   代码   以减少   rewrite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!