C# 将2个文本框转换为1个变量,用于C中的身高和体重转换#

C# 将2个文本框转换为1个变量,用于C中的身高和体重转换#,c#,C#,我正在创建一个需要身高和体重的程序。身高必须以英尺和英寸计算,体重必须以石头和磅计算。这需要2个文本框 我的问题是如何让文本框变成一个变量 在文本框更改或按钮中使用此功能单击: public long CalculateUnit(int flag , int number) //flag=Textbox Type { if(flag==1) { int totalInches = (number / 2.54); // This will take a floor function of Ce

我正在创建一个需要身高和体重的程序。身高必须以英尺和英寸计算,体重必须以石头和磅计算。这需要2个文本框


我的问题是如何让文本框变成一个变量

在文本框更改或按钮中使用此功能单击:

public long CalculateUnit(int flag , int number) //flag=Textbox Type
{

if(flag==1)
{
int totalInches = (number / 2.54); // This will take a floor function of Centimetres/2.54
int Feet = (totalInches - totalInches % 12) / 12; // This will make it divisible by 12
int inches = totalInches % 12; // This will give you the remainder after you divide by 12
result=inches; //or Feet
}
if(flag==2)
{
int Stone =number;
int Pounds = (Stone*14) ;
int Kilograms = (Pounds/2.2);
result=Kilograms; // or Pounds
}

return result;
}
}

您可以从两个文本框中获取值并将其连接。您可以创建一个类(或结构)
参数
,其中包含两个公共成员height和weight,并将变量声明为type
Parameters
。或者你的意思不同?这并不能回答问题请不要提倡使用一些“魔法”int标志。为此使用枚举,或者更好地对不同的用例使用不同的方法。是的,枚举更好。但我的例子是上面问题@poke的快捷函数