Tag: integer

Converting an Enum to Integer in C#

If you need to convert an enum to its numeric equivalent , you can simply cast the values to integer . Below is a sample code snippet that demonstrates how to do it. Converting an Enum to Integer in C#

How to Allow Null Values for Integer in C# ?

In order to allow null values to an integer or for any value types , we need to make the data type as Nullable<T> where T refers to type. How to Allow Null Values for Integer in C# ? There are 2 ways you can set null value to value types in C# .

How to Convert Integer to Hex and Vice versa in C# ?

If you want to convert an integer value to a hexa decimal value in C# and hexa decimal value to integer , you can use the “X” string formatting specifiers and the int.parse method with the method over loading option. How to Convert Integer to Hex and Vice versa in C# ? The code snippet to demonstrate the conversion of the integer value to hexa…

How to Parse a string to Nullable Int in C# ?

Below is a sample code snippet demonstrating how you can convert a string to Nnullable Int in C#. How to Parse a string to Nullable Int in C# ? We use the int.Parse and based on its return value , assign the null or integer value to the Nullable Int.

How to Convert a Byte Array to Integer in C# ?

To Convert a Byte array back to the integer , the developers can use the BitConverter.ToInt32 method which accepts byte array as input and returns the number . Below is a sample code snippet that demonstrates how to convert a byte array to integer in C#. How to Convert a Byte Array to Integer in C# ?

Padding Zeroes to an integer value in C#

If you need to prefix zeroes to an integer when converting it to string values , you can do that by using the PadLeft method in c#. Just specify the number of characters to prefix (padding) and the charater to prefix to the method and you are done 🙂 Below is a sample sourcecode to demonstrate Padding Zeroes to an integer value in C#

How to convert a string to integer in C# ?

You can convert a string to integer in C# using the following functions 1. Int32.Parse / int.Parse 2. Convert.ToInt32 3. Int.TryParse() How to convert a string to integer in C# ? Below is a sample sourcecode demonstrating the usage of the above functions The advantage of using the int.tryparse is that when the string (str) in the above example is a invalid number , a…