protected readonly long _value;
public MyNumber(string source)
if (!long.TryParse(source, out _value)) throw new ArgumentException("String cannot be converted to a MyNumber");
if (_value <=0) throw new ArgumentException("MyNumber must be at least 1.");
if (_value > 9999999999) throw new ArgumentException("MyNumber must be ten digits or fewer.");
static public implicit operator long(MyNumber source)
static public implicit operator MyNumber(string source)
return new MyNumber(source);
public long Value { get { return _value; } }
public override string ToString()
return _value.ToString("000 000 0000");
public static void Main()
Console.WriteLine("Your magic number is {0}", n);
Console.WriteLine("Another number is {0}", (MyNumber)"9876543");