User FAQs

If you have a question, please send it to us.


1) Can you convert a string to an integer data type ?
Yes. There are several ways this can be done.

int i; 
i = (int)myString;
i = (System.Int32)myString;
i = myString as int;
i = myString as System.Int32;
i = System.Convert.ToInt32(myString);
i = System.Int32.Parse(myString);

2) Can you convert an integer to a string data type ?
Yes. There are several ways this can be done.

int i = 10; 
string s;
s = i.ToString();
s = System.Convert.ToString(i);
s = System.String.Format("{0}",i);
s = $"{i}";
s = "" + i;
s = System.String.Empty + i;
s = new System.Text.StringBuilder().Append(i).ToString();

3) Can you describe the byte data type ?
The System.Byte data type is used to



4) Can you describe the short data type ?
The System.Int16 data type is used to



5) Can you describe the int data type ?
The System.Int32 data type is used to
In .NET 4.7 you can use an underscore in a numerical literal to make it more readable.

int myInteger = 1_000_000; 


6) Can you describe the long data type ?
The System.Int64 data type is used to

long myLong = 5L; 


7) Can you describe the float data type ?
The System.Single used to store Single Precision floating point.

float myFloat = 4.5F; 

8) Can you describe the double data type ?
The System.Double data type is used to store Double Precision floating point.
The range is -1.797 E308 to 1.797 E308

double myDouble = 4.0; 
double myDouble = 4.0D;
double myDouble = 1E06;

9) Can you describe the decimal data type ?
The System.Decimal data type is used to store Exact Precision floating point.
The range is 1 E-28 to 7.9 E28.
This data type should be used for all financial calculations

decimal myDecimal = -1.23M 

10) What is the difference between the double and decimal data types?



11) What is Arithmetic Overflow and Underflow ?
When you perform an integer arithmetic operation and the result goes outside the range of the data type.
To modify and control overflow/underflow there are two keywords you can use 'checked' and 'unchecked'.
In a checked context, arithmetic overflow raises an exception.
In an unchecked context, arithmetic overflow is ignored and the result is truncated or wrapped. This is the default context.
Code where unexpected wrapping arithmetic needs to be detected you should use checked context.
Code that relies on wrapping arithmetic should use unchecked context.

int myInt = 2147483647 + 10; 
// this line generates a compile-time error

int number = 10
int myInt2 = 2147483647 + number;
// this line does not generate a compile time error or a run-time exception

checked
{
   int number = 10;
   int myInt2 = 2147483647 + number;
    // this line generates an overflow run-time exception
}

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext