English 中文(简体)
C# 多式文本箱的答复总是 1
原标题:C# Multiply textboxes answer always 1

我对以下法典有问题。

bool TextBox2INT = true;
bool TextBox1INT = true;

int outputValue = 0;
int ButtonFind;

int TextBox1INT2 = Convert.ToInt32(TextBox1INT);
int TextBox2INT2 = Convert.ToInt32(TextBox2INT);

TextBox2INT = int.TryParse(textBox2.Text, out outputValue);
TextBox1INT = int.TryParse(textBox1.Text, out outputValue);

ButtonFind = (int)Math.Round((double)(TextBoxt1INT2 * 0.0333m * TextBox2INT2) + (double)(TextBox1INT2));
textBoxFind.Text = ButtonFind.ToString();

问题在于,该法典完全是有效的,但在案文BoxFind中将答案分解时。 案文总是 1. 导言

最佳回答

页: 1

我认为你指的是:

int TextBox1INT2, TextBox2Int2;

bool textBox1Valid = int.TryParse(textBox2.Text, out TextBox1INT2);
bool textBox2Valid = int.TryParse(textBox1.Text, out TextBox2INT2);

如果有的话,请采取行动。 TryParse 回报不实,例如,告诉用户进入有效号码,而不是进行计算。 我也更改了你的可变名称,因此,你有:

int parsedTextBox1, parsedTextBox2;

bool textBox1Valid = int.TryParse(textBox2.Text, out parsedTextBox1);
bool textBox2Valid = int.TryParse(textBox1.Text, out parsedTextBox2);

if (!textBox1Valid || !textBox2Valid)
{
    // Do something to warn the user here, e.g. a message box
    return;
}

double result = (parsedTextBox1 * 0.0333m * parsedTextBox2) + parsedTextBox1;
textBoxFind.Text = ((int) Math.Round(result)).ToString();
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签