Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int a = 10, b = 6;

            Console.WriteLine(Arithmitic.Add(a, b));
            Console.WriteLine(Arithmitic.Subtract(a, b));
            Console.WriteLine(Arithmitic.Multiply(a, b));
            Console.WriteLine(Arithmitic.Divide(a, b));
            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main1(string[] args)
        {
            List <Animal> animalLists = new List <Animal>();

            // we can create a list of standar type
            List <int> intlist = new List <int>();

            intlist.Add(24);

            // add
            animalLists.Add(new Animal()
            {
                Name = "cat1"
            });
            animalLists.Add(new Animal()
            {
                Name = "cat2"
            });
            animalLists.Add(new Animal()
            {
                Name = "cat3"
            });
            animalLists.Add(new Animal()
            {
                Name = "cat4"
            });
            // insert at index
            animalLists.Insert(1, new Animal()
            {
                Name = "cat5"
            });

            // Remove index 1
            animalLists.RemoveAt(2);

            // count the size
            Console.WriteLine($"number of animals is {animalLists.Count}");



            // list<T>, arraylist<T> dictionary<T,T> queue<T> stack<T>
            int x = 4, y = 5;

            Animal.GetSum <int>(ref x, ref y);

            string xstr = "4", ystr = "5";

            Animal.GetSum(ref xstr, ref ystr);

            // example with struct
            Rectangle <int> rect = new Rectangle <int>(20, 50);

            Console.WriteLine(rect.GetArea());

            Rectangle <string> rect1 = new Rectangle <string>("20", "50");

            Console.WriteLine(rect1.GetArea());

            ///
            animalHealt h1 = new animalHealt();
            animalHealt h2 = new animalHealt();
            //Animal.GetSum(ref h1, ref h2);

            // delegate
            Arithmitic add, sub, addSub;

            add = new Arithmitic(Add);

            sub = new Arithmitic(Sub);

            addSub = add + sub;

            add(4, 5);
            sub(6, 3);
            addSub(2, 7);

            string response = Console.ReadLine();

            /*switch (response)
             *  {
             *  case "add"
             *      add = Arith ...
             * }
             */
            Console.ReadLine();
        }