Esempio n. 1
0
        internal static Boolean Box(bool byPass)
        {
            if (!byPass)
            {
                try
                {
                    int    myInt    = 20;
                    object intBoxed = myInt;

                    long   myLongNumber = 3333333333333;
                    object mObj         = (object)myLongNumber;
                    int    mInt         = (int)mObj;
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            //More Boxing
            Cur    cur  = new Cur(100, 10);
            object oCur = cur;
            object nObj = new object();

            Cur dCur = (Cur)oCur;

            try
            {
                Cur eCur = (Cur)nObj;
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
        public static void Main()
        {
            //Type Cons
            long val = 300000000000;

            try {
                int i = checked ((int)val);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message}");
            }

            ushort c   = 43;
            char   sym = (char)c;

            Console.WriteLine(sym);

            double[] Prices = { 10.90, 20.25, 15.33, 34.99 };

            Items items;

            items.Descp    = "Red Bottle";
            items.AppPrice = (int)(Prices.Average());


            try
            {
                int?a = null;
                int b = checked ((int)a);
            }
            catch (Exception)
            {
            }

            Boolean res = BoxUnBox.Box(false);

            res = TypeSafe.sTypeSafe();

            OpOverloading oL = new OpOverloading();

            res = oL.eTest(null);
            res = oL.eTest("Dave");

            MVector sVec = new MVector(1, 2, 3);
            MVector eVec = new MVector(4, 5, -3);
            MVector rVec = sVec + eVec;

            Cons.WriteLine($"sVec {sVec.ToString()} + eVec {eVec.ToString()} = rVec {rVec.ToString()}.");

            rVec = 2 * sVec;
            rVec = (sVec * 3) * 3;

            double r = sVec * eVec;

            Cons.WriteLine($"{sVec} * {eVec} in dot notation = {r}");

            rVec -= eVec;
            Cons.WriteLine($"rVec -= eVec gives us {rVec}");

            Cur       w    = new Cur(32200, 33);
            SimpleCur sCur = new SimpleCur("Dave", w);

            float aAmount = 4500.12f;
            Cur   cAmount = (Cur)aAmount;

            //The Issue
            try
            {
                Cur   bal  = new Cur(50, 35);
                float fBal = bal;
                bal = (Cur)fBal;

                checked   //This is not needed when Checked in Cur operator.
                {
                    bal = (Cur)(-555.33);
                }
            }
            catch (Exception ex)
            {
                Cons.WriteLine("Exception is {0}", ex.Message);
            }


            //More Boxing unBoxing
            Boolean res2 = BoxUnBox.Box(true);
        }
Esempio n. 3
0
 public SimpleCur(string name, Cur wage)
 {
     _name = name;
     _wage = wage;
 }