0
Try this:
using System;
class MyClass
{
string numericString = "0"; // default value
public string NumericString
{
get { return numericString; }
set
{
double number;
bool isValid = double.TryParse(value, out number);
if (isValid)
numericString = number.ToString();
else
throw new ArgumentException(String.Format("'{0}' is not a numeric string", value));
}
}
}
class Program
{
static void Main()
{
MyClass mc = new MyClass();
try
{
mc.NumericString = "12.34";
mc.NumericString = "abc";
}
catch(ArgumentException ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
}