Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设有两个文本框:在一个文本框中,用户输入“5”,然后在第二个文本框中,用户输入 5 个数字“1 2 3 4 5”,计算机必须将文本框中的这 5 个数字加在一起,然后显示它们。
我怎样才能做到这一点?
最简单的方法可能是:
var numbersText = yourTextBox2.Text; var allNumbersAddedUp = numbersText.Split(' ').Select(int.Parse).Sum();
不要忘记
using System.Linq;
这与用户在第一个文本框中输入的内容无关。
由于这似乎是教科书作业,请自己做作业,阅读教科书并自己学习,而不是使用互联网上的现成解决方案。有一天我将不得不和你一起工作,我想和那些学会了这一点的人一起工作,而不是从互联网上的某个地方复制它。