在C#中使用模数编码
大家好。我目前正在进行基础编程和逻辑课程。我的项目是创建一个简单的计算器。除了模数按钮,我写了所有内容。我在网上搜索试图找到如何编码,但我无法找到我需要的确切内容。我知道模数可以找到两个数之间的余数。我要做的是将第一个数字输入txtbox,点击模数按钮,然后输入第二个数字并点击相等。我迷失在如何编码这个。请教我一些东西,哦代码大师。我99%完成了这个项目。
谢谢大家,提前花时间回答。
Hello all. I am currently in a Fundamental Programming and Logic class. My project is creating a simple calculator. I have everything written except for the modulus button. I have searched the web trying to find how to code this but am unable to find exactly what I am needing. I understand that modulus finds the remainder between two numbers. What I am trying to do is take the first number entered into the txtbox, hit the modulus button then enter the second number and hit equal. I am lost on how to code this. Please teach me something, oh gurus of code. I''m 99% done with this project.
Thank you all, ahead of time, for taking time to answer.
这是一个你需要的工作实例:
Here is a working example of what you need:
string[] s = TextBox1.Text.ToString().Split(''%'');
int n = 0;
if (TextBox1.Text.ToString().Contains("%"))
{
n = Convert.ToInt32(s[0].ToString()) % Convert.ToInt32(s[1].ToString());
}
Label1.Text = n.ToString();