Friday, October 8, 2010

Example of Static class, Extension methods, Comma Sepated Integers and Check String for Interger

When ever we want create a extension methods, the class should be static.
This example describes how is static class, how to write Extension methods.
We have two regex values one for checking comma sepated integers and checking for the integer.
public static class ValidationHelper
{
const string m_pattern = "^([0-9]*)$"; or ("\d+")
public static bool CheckString(this string str)
{
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(m_pattern);
return (r.Match(str).Success);

}
public static bool CheckCommaSepateIntegers(this string commastrinrg)
{
System.Text.RegularExpressions.Regex cerficateverify = new System.Text.RegularExpressions.Regex(@"^\d+(,\d+)*$");
return (cerficateverify.Match(commastrinrg).Success);
}
}

No comments:

Post a Comment