Convert String Representation of a Number to its 32 bit Signed Integer

Convert String Representation of a Number to its 32 bit Signed Integer

30/05/2020 0 By Laurence

Problem: I have a string (let’s say ‘7’) and I want this to be read as a number (as in integer) so we can perform a math calculation.

Solution: Convert it to a signed integer as follows:

num1 = Int32.Parse(textboxFirstNumber.Text);

Explanation:

  • num1 is a variable of string data type.
  • we are saying that whatever is entered into the textbox by the use equals num1.
  • but we cannot perform a calculation between operands using a string, even though the user text input seems to be written as a number.
  • to perform the calculation we need the string to become a number (an integer).
  • we use Int32.parse to undertake the conversion.

Data Types

Data types are associated with memory allocation.

The downloadable file below is from: https://www.tutorialspoint.com/csharp/csharp_data_types.htm