예제 #1
0
        public static AndClass1 operator +(AndClass1 op1, AndClass1 op2)
        {
            AndClass1 returnVal = new AndClass1();

            returnVal.Val = op1.Val + op2.Val;
            return(returnVal);
        }
예제 #2
0
        public static AndClass1 operator -(AndClass1 op1)
        {
            AndClass1 returnVal = new AndClass1();

            returnVal.Val = -op1.Val;
            return(returnVal);
        }
예제 #3
0
        static void Main(string[] args)
        {
            Animals2 animalCollection2 = new Animals2();

            animalCollection2.Add("Animal0", new Animal("popo"));
            foreach (DictionaryEntry myEntry in animalCollection2)
            {
                WriteLine($"New {myEntry.Value.ToString()} object added to " +
                          $"custom collection, Name = {((Animal)myEntry.Value).Name}");
            }

            Animals3 animalCollection3 = new Animals3();

            animalCollection3.Add("Animal0", new Animal("gaolbird"));
            foreach (Animal myAnimal in animalCollection3)
            {
                WriteLine($"New {myAnimal.ToString()} object added to " +
                          $"custom collection, Name = {myAnimal.Name}");
            }

            foreach (string item in SimpleList())
            {
                WriteLine(item);
            }

            Cloner mySource = new Cloner(5);
            Cloner myTarget = (Cloner)mySource.Clone();

            WriteLine($"myTarget.MyContent.Val = {myTarget.MyContent.Val}");
            mySource.MyContent.Val = 2;
            WriteLine($"myTarget.MyContent.Val = {myTarget.MyContent.Val}");
            myTarget.MyContent.Val = 10;
            WriteLine($"myTarget.MyContent.Val = {myTarget.MyContent.Val}");
            WriteLine($"mySource.MyContent.Val = {mySource.MyContent.Val}");

            MyStruct valType1 = new MyStruct();

            valType1.Val = 5;
            IMyInterface refType = valType1;

            valType1.Val = 6;
            MyStruct valType2 = (MyStruct)refType;

            WriteLine($"valType2.Val = {valType2.Val}");
            WriteLine();

            AndClass1 op1 = new AndClass1();

            op1.Val = 5;
            AndClass1 op2 = new AndClass1();

            op2.Val = 5;
            //WriteLine(op1 + op2);
            AndClass1 op3 = op1 + op2;

            WriteLine(op3.Val);
            WriteLine((-op3).Val);
            bool op4 = op1 == op2;

            WriteLine(op4);
            WriteLine();

            AndClass2 op5 = new AndClass2();

            op5.Val = 5;
            AndClass3 op6 = new AndClass3();

            op6.Val = 5;
            AndClass4 op7 = op5 + op6;

            op7 = op6 + op5;
            WriteLine(op7.Val);
            WriteLine();


            string firstString  = "Fisrt String";
            string secendString = "Second String";

            WriteLine($"Comparing '{firstString}' and '{secendString}' " + $"result: {Comparer.Default.Compare(firstString,secendString)}");
            int firstNumber  = 35;
            int secondNumber = 13;

            WriteLine($"Comparing '{firstNumber}' and '{secondNumber}' " + $"result: {Comparer.Default.Compare(firstNumber, secondNumber)}");

            ConvClass1 op01 = new ConvClass1();

            op01.Val = 3;
            ConvClass2 op02 = op01;

            ConvClass2 op03 = new Ch11Ex00.ConvClass2();

            op03.Val = 3e5;
            ConvClass1 op04 = (ConvClass1)op03;

            test();
            ReadKey();
        }