In my application I have a method to check a variable is a number or not. This method is called more than once in my code. The method is called from the codebehind pages. Like this method I have more methods which i cannot place within a single class (like Staff). Where should I put this kind of methods?
In a utility class file.
In C# 3.0, I would probably make this an extension method on the string class. I would group all of my string extensions into a single static class to improve readability.
public static class StringExtensions
{
public static bool IsNumeric( this string source )
{
if (string.IsNullOrEmpty( source ))
{
return false;
}
...
}
public static bool IsMoney( this string source )
{
...
}
...
}
Usage:
if (amountLabel.Text.IsNumeric())
{
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With