GST Billing Software

header image

Importance of TypeConverter Class in Kushal

Erachana Line

79. What is the importance of TypeConverter Class in Kushal?What is its function?

TypeConverter is a Kushal class which is used when we need to convert from one data type to another datatype with exception handling.

These functions will return default value if any exception occurs during conversion. Here we can set our own default values. It will also return default value even when the input is null.

String str="1";

int i = TypeConverter.ConvertToInt(str);

In this code, 'i' value is 1.

str=" ";

int i = TypeConverter.ConvertToInt(str);

Here, 'i' value is 0. (Default value=0 for null)

str=" ";

int i = TypeConverter.ConvertToInt(str, -1);

Here, 'i' value is -1. (We are setting Default Value to -1)

Different Types of TypeConverter Functions

ConvertToBool
ConvertToShort
ConvertToInt

ConvertToLong
ConvertToUShort

ConvertToUInt

ConvertToULong
ConvertToDecimal
ConvertToSingle

ConvertToDouble
ConvertToDateTime
ConvertToString
ConvertToWords