Skip to main content
Update description
Source Link
JimmyHu
  • 5.5k
  • 2
  • 10
  • 40

Review

It seems that you are trying to make a simple calculator with number comparison in C#. There are some problems in this implementation.

ToInt32:

Do you expect the input of calculation is always in int format? How about floating numbers?

Nah method:

  • NamingNaming:

    I have no idea how's the name Nah imply the operation in the method. Something like run or perform are better than Nah.

  • Integer DivisionInteger Division:

    Notice that the execution of 3 / 2 in this implementation is 1. It is a kind of integer division. Is the integer division result the correct output you expected?

  • MessageBox.Show PartMessageBox.Show Part:

    In C# 6, you can use string interpolation and make MessageBox.Show("Sum of thenumbers entered is: " + (a + b)); into MessageBox.Show($"Sum of thenumbers entered is: {(a + b)}");. Interpolated strings are useful in string displaying and it's commonly used with Console.WriteLine or MessageBox.Show.

Error Handling

  • Null or empty string:

    You use textBox1.Text and textBox2.Text as a way to read numbers from user input. How about the case of empty strings (user click button Check directly without type any character)? If textBox.Text passes in Convert.ToInt32 directly and the content is empty, System.FormatException will occur. Maybe String.IsNullOrEmpty check can be used here.

  • DivideByZeroException

    DivideByZeroException Class can be used to handle an attempt to divide an number by zero.

Review

It seems that you are trying to make a simple calculator with number comparison in C#. There are some problems in this implementation.

ToInt32:

Do you expect the input of calculation is always in int format? How about floating numbers?

Nah method:

  • Naming:

    I have no idea how's the name Nah imply the operation in the method. Something like run or perform are better than Nah.

  • Integer Division:

    Notice that the execution of 3 / 2 in this implementation is 1. It is a kind of integer division. Is the integer division result the correct output you expected?

  • MessageBox.Show Part:

    In C# 6, you can use string interpolation and make MessageBox.Show("Sum of thenumbers entered is: " + (a + b)); into MessageBox.Show($"Sum of thenumbers entered is: {(a + b)}");. Interpolated strings are useful in string displaying and it's commonly used with Console.WriteLine or MessageBox.Show.

Review

It seems that you are trying to make a simple calculator with number comparison in C#. There are some problems in this implementation.

ToInt32:

Do you expect the input of calculation is always in int format? How about floating numbers?

Nah method:

  • Naming:

    I have no idea how's the name Nah imply the operation in the method. Something like run or perform are better than Nah.

  • Integer Division:

    Notice that the execution of 3 / 2 in this implementation is 1. It is a kind of integer division. Is the integer division result the correct output you expected?

  • MessageBox.Show Part:

    In C# 6, you can use string interpolation and make MessageBox.Show("Sum of thenumbers entered is: " + (a + b)); into MessageBox.Show($"Sum of thenumbers entered is: {(a + b)}");. Interpolated strings are useful in string displaying and it's commonly used with Console.WriteLine or MessageBox.Show.

Error Handling

  • Null or empty string:

    You use textBox1.Text and textBox2.Text as a way to read numbers from user input. How about the case of empty strings (user click button Check directly without type any character)? If textBox.Text passes in Convert.ToInt32 directly and the content is empty, System.FormatException will occur. Maybe String.IsNullOrEmpty check can be used here.

  • DivideByZeroException

    DivideByZeroException Class can be used to handle an attempt to divide an number by zero.

Source Link
JimmyHu
  • 5.5k
  • 2
  • 10
  • 40

Review

It seems that you are trying to make a simple calculator with number comparison in C#. There are some problems in this implementation.

ToInt32:

Do you expect the input of calculation is always in int format? How about floating numbers?

Nah method:

  • Naming:

    I have no idea how's the name Nah imply the operation in the method. Something like run or perform are better than Nah.

  • Integer Division:

    Notice that the execution of 3 / 2 in this implementation is 1. It is a kind of integer division. Is the integer division result the correct output you expected?

  • MessageBox.Show Part:

    In C# 6, you can use string interpolation and make MessageBox.Show("Sum of thenumbers entered is: " + (a + b)); into MessageBox.Show($"Sum of thenumbers entered is: {(a + b)}");. Interpolated strings are useful in string displaying and it's commonly used with Console.WriteLine or MessageBox.Show.