using System;

namespace Example
{
    public class Test4 
    {
        public string strMyValue;
        public Test4()
        {
            Console.WriteLine("Test4 () Constructor");
            strMyValue = "Doh!";
        }
        public Test4(string inMyValue)
        {
            Console.WriteLine("    Test4 ({0}) Constructor", inMyValue);
            strMyValue = inMyValue;
        }
        ~Test4()
        {
            Console.WriteLine("    Test4 Finalize [{0}]", strMyValue);
        }
        //here we overide the implicit string conversion
        public static implicit operator string(Test4 t)
        {
            return "Test4:("+t.strMyValue+")";
        }
        //and here we add a conversion to int
        public static implicit operator int(Test4 t)
        {
            return 42;
        }

    }

    public class ImplicitExample
    {
        static public object objHolder;  // defaults to null

        static void Main(string[] args)
        {
            object one;
            
            Console.WriteLine("BEGIN:");
            Console.WriteLine("  Create a new Test4");
            one = new Test4("blah");
            Console.WriteLine("      one ->"+one);
            Console.WriteLine("      (Test4)one->"+(Test4)one);
            Console.WriteLine("      (int)(Test4)one->"+(int)((Test4)one));
            Console.WriteLine("  Destruct our Test4");
            one = null;
            Console.WriteLine("END");
        }
    }
}