Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Text.RegularExpressions;
Namespace Typeclass
{
public class Typeparse
{
<summary>
A number that determines whether an object is a Int32 type
</summary>
<param name= "Expression" ></param>
<returns></returns>
public static bool IsNumeric (object Expression)
{
if (Expression!= null)
{
int intval;
return int. TryParse (Expression.tostring (), out intval);
}
return false;
}
public static bool Isdouble (object Expression)
{
if (Expression!= null)
{
Double Doubleval;
Return double. TryParse (Expression.tostring (), out doubleval);
}
return false;
}
<summary>
Convert string to type bool
</summary>
<param name= "strvalue" > string to convert </param>
<param name= "Defvalue" > Default value </param>
<returns> conversion of bool type result </returns>
public static bool Strtobool (object Expression, bool defvalue)
{
if (Expression!= null)
{
BOOL Boolvalue;
if (BOOL). TryParse (Expression.tostring (), out boolvalue))
return boolvalue;
Else
return defvalue;
}
return defvalue;
}
<summary>
Convert an object to a Int32 type
</summary>
<param name= "strvalue" > string to convert </param>
<param name= "Defvalue" > Default value </param>
<returns> Int32 type results after conversion </returns>
public static int Strtoint (object Expression, int defvalue)
{
if (Expression!= null)
{
int intvalue;
if (int. TryParse (Expression.tostring (), out intvalue))
return intvalue;
Else
return defvalue;
}
return defvalue;
}
<summary>
Convert string to float type
</summary>
<param name= "strvalue" > string to convert </param>
<param name= "Defvalue" > Default value </param>
<returns> float-type results after conversion </returns>
public static float Strtofloat (object strvalue, float defvalue)
{
if (strvalue!= null)
{
float Floatvalue;
if (float. TryParse (Strvalue.tostring (), out Floatvalue))
return floatvalue;
Else
return defvalue;
}
return defvalue;
}
<summary>
Convert String to decimal type
</summary>
<param name= "strvalue" > string to convert </param>
<param name= "Defvalue" > Default value </param>
<returns> Decimal Type results after conversion </returns>
public static decimal Strtodecimal (object strvalue, decimal defvalue)
{
if (strvalue!= null)
{
Decimal Decimalvalue;
if (Decimal.tryparse (strvalue.tostring (), out Decimalvalue))
Return Math.Round (decimalvalue,2);
Else
return defvalue;
}
return defvalue;
}
<summary>
Convert String to datetime type
</summary>
<param name= "strvalue" > string to convert </param>
<param name= "Defvalue" > Default value </param>
<returns> datetime type results after conversion </returns>
public static datetime Strtodatetime (Object strvalue, DateTime defvalue)
{
if (strvalue!= null)
{
DateTime Datetimevalue;
if (Datetime.tryparse (strvalue.tostring (), out Datetimevalue))
return datetimevalue;
Else
return defvalue;
}
return defvalue;
}
<summary>
Determines whether the data in a given string array (Strnumber) is numeric
</summary>
<param name= "Strnumber" > Array of strings to confirm </param>
<returns> is return to true is not returned false</returns>
public static bool Isnumericarray (string[] strnumber)
{
if (Strnumber = null)
{
return false;
}
if (Strnumber.length < 1)
{
return false;
}
foreach (string ID in Strnumber)
{
if (! IsNumeric (ID))
{
return false;
}
}
return true;
}
}
}