Hi
public static class CommonFunction
{
public static bool IsAlphaNumericWithUnderscore(string input)
{
return Regex.IsMatch(input, "^[a-zA-Z0-9_]+$");
}
public static bool IsAllLetters(string s)
{
foreach (char c in s)
{
if (!Char.IsLetter(c))
return false;
}
return true;
}
}
Thanks
Gowtham CpPosted Aug 17, 2024, 7:49 AM
In C#,
staticmeans that a class or its members belong to the class itself rather than to any individual instance. For example, with theCommonFunctionclass, you don’t create an object to use its methods. Instead, you call methods likeIsAlphaNumericWithUnderscoreandIsAllLettersdirectly on the class itself. This makesstaticmembers useful for utility functions that are shared across all uses of the class.Here, you can use
CommonFunction.IsAlphaNumericWithUnderscore("Test_123")orCommonFunction.IsAllLetters("HelloWorld")directly without creating an instance ofCommonFunction.