如何用几行代码制作无限变量? [英] How can I make unlimited variables with a couple lines of code?

查看:83
本文介绍了如何用几行代码制作无限变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个可以接受无限输入并将其相加的程序.输入内容将被放置在文本框中,并通过按钮提交.有任何建议吗?

I''m trying to create a program that can accept infinite inputs and add them up. The input will be put in a text-box and submitted with a button. Any suggestions?

推荐答案

//u need to add  System.Text.RegularExpressions;
//Input is ur input string
string[] Numbers = Regex.Split(Input, @"\D+");
int Temp=0,Sum=0;
foreach(string i in Numbers)
if(int.TryParse(i,out Temp))
Sum += Temp;


上面的代码仅包含数字.
跳过所有非数字字符,因此要分隔任何数字,请使用任何非数字字符


Above code will take only Numbers.
Skips all Non-Digit characters, so to separate any number use any Non-Digit character


这篇关于如何用几行代码制作无限变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆