Well, to verify that the input is actually an object of type System.String, you can simply do:
bool IsString(object value)
{
return value is string;
}
To make sure that a stringcontains only letters, you can do something like this:
bool IsAllAlphabetic(string value)
{
foreach (char c in value)
{
if (!char.IsLetter(c))
return false;
}
return true;
}
If you want to combine them, you can do this:
bool IsAlphabeticString(object value)
{
string str = value as string;
return str != null && IsAllAlphabetic(str);
}
source
share