Vb de olmasına rağmen c# ta olmayan ve bir ifadenin sayısal olup olmadığını kontrol eden metodu c# ta aşağıdaki yöntemlerle yapabilirsiniz.
1.yol
public bool IsNumeric(string text)
{
return Regex.IsMatch(text,"^\\d+$");
}
2.yol
public bool IsNumeric(string numberString)
{
char [] ca = numberString.ToCharArray();
for (int i = 0; i < ca.Length;i++)
{
if (ca[i] > 57 || ca[i] < 48)
return false;
}
return true;
}
3.yol
public bool IsNumeric(string numberString)
{
char [] ca = numberString.ToCharArray();
for (int i = 0; i < ca.Length;i++)
{
if (!char.IsNumber(ca[i]))
return false;
}
return true;
}
4.yol
public bool IsNumeric(object Expression)
{
bool isNum;
double retNum;
isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any,System.Globalization.NumberFormatInfo.InvariantInfo, out retNum );
return isNum;
}
iyi çalışmalar
Mustafa KOÇER
mkocer@dotnetkosesi.com
Bu yazıyı ilk değerlendiren siz olun
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5