C# 如何使数字之间的“while”循环计数?

C# 如何使数字之间的“while”循环计数?,c#,C#,我有一个程序,有两个文本框输入。它们是可变的一和可变的二。我想不出我需要放在for循环中的表达式来显示这些数字以及它们之间的数字。例如,如果我把1和11放在两者之间,我需要2-10。这就是我到目前为止所拥有的。。我知道我也没有其他的表达方式 namespace loops { public partial class Form1 : Form { public Form1() { InitializeComponent()

我有一个程序,有两个文本框输入。它们是可变的一和可变的二。我想不出我需要放在for循环中的表达式来显示这些数字以及它们之间的数字。例如,如果我把1和11放在两者之间,我需要2-10。这就是我到目前为止所拥有的。。我知道我也没有其他的表达方式

namespace loops
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void whileButton_Click(object sender, EventArgs e)
        {
            double variableOne = 0;
            double variableTwo = 0;
            int i = 0;


            if (double.TryParse(variableOneText.Text, out variableOne))
            {
                if(double.TryParse(variableTwoText.Text, out variableTwo))
                {
                    while(i<= (variableOne) && (variableTwo))
                    {
                        i++;
                    }
                    outputLabel.Text = i.ToString();

                }

            }
        }
    }
}

现在还不清楚你想要实现什么

我在这里猜测:

输入:两个有理数。 输出:介于两者之间的所有自然数

e、 g.在8.1、14.9中->在9、10、11、12、13中

这是密码

StringBuilder output = new StringBuilder();
double variableOne = 8.1;
double variableTwo = 14.9;

double start = 0;
double end = 0;

bool isShowingInitialVariable = true;


//if (double.TryParse(variableOneText.Text, out variableOne))
//{
//    if (double.TryParse(variableTwoText.Text, out variableTwo))
//    {


//take allways the smaller number to start and the greater for end
start = Math.Min(variableOne, variableTwo); 
end = Math.Max(variableOne, variableTwo);

//build your output
output.AppendLine(string.Format("first variable {0}, second variable {1}", variableOne, variableTwo));
output.AppendLine(string.Format("min", start));
output.AppendLine(string.Format("max", end));
output.AppendLine(string.Format("difference {0}", end - start));


//all the natural numbers in between.
for (int i = (int)Math.Ceiling(start); i < Math.Floor(end); i++)
{
    output.AppendLine(i.ToString());
}

Console.WriteLine(output.ToString());
//        outputLabel.Text = output.ToString();

//    }

//}

向我们展示您的尝试。我很难理解您的问题我们可以帮助您编写代码,但没有人会为您编写代码,展示您到目前为止所做的一切好的,因此我必须输入第一个数字,例如,我输入1,然后我必须输入第二个数字表示10。我不知道在运算中应该放什么表达式。。这就是我到目前为止所拥有的..我知道我没有其他方法可以尝试,在单击Object sender(对象发送者)按钮时解析它们的私有空间,EventArgs e{double variableOne=0;double variableOne=0;int i=0;如果double.TryParsevariableOneText.Text,则输出variableOne{ifdouble.TryParsevariableTwoText.Text,out variableTwo{whilei