Ejemplo n.º 1
0
        // Main method.
        static void Main()
        {
            Console.WriteLine(Colors.Red);       // return enum key
            Console.WriteLine((char)Colors.Red); // return enum value


            Console.Title = "Console App Core";  // Title of the console screen.

            // calling class with non static method.
            Human mohamed = new Human(); // ahmed object from human , calling with object.

            mohamed.add(10, 20);         // return 30.

            // calling class with static method.
            Human.sum(10, 20);  // return 30.
            // above code it printing in memory.


            // hear printing from memory to user interfsce.
            System.Console.WriteLine(Human.sum(10, 20)); // without system libarary.


            // Example for swaping varibles.

            int a = 10;
            int b = 20;

            // swap a = 20 , b = 10 without using any temp varaible.
            b = a;         // b = 10.
            a = b + b;     // a = 10 + 10 = 20.

            int x = 99;
            int y = 101;

            //swap x = 101 , y = 99 without using any temp varaible.
            x = x + y;     // x = 99 + 101 = 200.
            y = x - y;     // y = 200 - 101 = 99.
            x = x - y;     // x = 200 - 99 = 101.


            Childs childs = new Childs();  // object from childs  >> has a relationship.

            Console.WriteLine(childs.age);

            Store Cairo = new Store();

            Console.WriteLine(Cairo.NumberOfReminingProduct(20));      // 20 requested quntity  >> 80 all quntity

            Store Ismailia = new Store();

            Console.WriteLine(Ismailia.NumberOfReminingProduct(30));   // 30 requested quntity  >> 50 all quntity

            Store Alex = new Store();

            Console.WriteLine(Alex.NumberOfReminingProduct(50));      // 50 requested quntity  >> 0 all quntity


            //  Demo d = new Demo();  // proccess 1   >>  time 1  : time of object creation.
            //d.PrintMe();          // proccess 2   >>  time 2  : time of calling to method.


            // when class have constructor
            Demo dc = new Demo(); // only 1 proccess and 1 time.

            // object with constructor overloding
            Demo dco = new Demo(); // only 1 proccess and 1 time.



            MyClass m1 = new MyClass();
            // Console.WriteLine(m1.name);

            MyClass m2 = m1;

            m2.name = "reco2";
            Console.WriteLine(m1.name);
            Console.WriteLine(m2.name);


            Reco r = Reco.createObj();

            r.speak();

            utilits u        = new utilits("reco"); // object from class with overload constructor.
            string  username = "******";
            string  password = "******";

            // fore loop
            for (int i = 0; i < 100; i++) // strucur of for loop with condition and incriment.
            {
                if (i % 2 == 0)
                {
                    if (i <= 9)
                    {
                        Console.WriteLine("even number :  " + i);
                    }
                    else
                    {
                        Console.WriteLine("even number : " + i);
                    }
                }

                else
                {
                    Console.WriteLine("odd  number :  " + i);
                }
            }

            // while
            int index = 0;

            while (index < 10)
            {
                Console.WriteLine(index);
                index++;
            }

            // do while
            int val = 0;

            do
            {
                Console.WriteLine(val);
                val++;
            }while (val < 8);

            //foreach

            // inline if  , // ternary operator {dision making}.
            string answer = "good";
            string result = (answer == "good") ? "good job" : "bad job";

            Console.WriteLine(result);


            //if else

            if (username == "ahmed" && password == "123456")
            {
                Console.WriteLine("login success ... ");
            }

            else
            {
                Console.WriteLine("login faild ...");
            }

            //if elseif else
            if (username == "ahmed" && password == "123456")
            {
                Console.WriteLine("login success ... ");
            }

            else if (username == "ahmed" || password == "123456")
            {
                Console.WriteLine("login simi success .... ");
            }

            else
            {
                Console.WriteLine("login faild ... ");
            }

            //swich case comapre between value and value only  >>  like if else but cant using multi operators.
            int myAge = 20;

            switch (myAge)
            {
            case 20:
                Console.WriteLine("same age");
                break;      // end proccess

            case 30:
                Console.WriteLine("not match");
                break;      // end proccess

            default:
                Console.WriteLine("plz chose");     //like else
                break;
            }


            int    xa = 5;
            double ya = 7.3;

            // working with casting ...

            xa = (int)ya; // explicit casting
            ya = xa;      // implicit casting

            // another implicit casting
            var s = "hi"; // string
            var d = 5;    // int

            Console.WriteLine(s + d);
            // working with Anonymous types

            Demo rr            = new Demo();
            var  rrr           = new Demo();
            var  anonymousType = new { name = "reco ", age = 25, salary = 1000 };

            Console.WriteLine(anonymousType.name);


            // daynamic type it's can evaluate the compile time at same run time
            dynamic uu  = 20; // runtime
            var     uuu = 50; // compile time

            Console.WriteLine(uuu);

            const double PI = 3.14; // cannot be re-intialize

            // PI = 15.5; // > error
            Console.WriteLine(PI);


            Ireport ireport = new PDFReport();

            ireport.Header();
            ireport.Body();
            ireport.Footer();


            // example of arrays
            // 1- single dimention array

            int[] ages = { 10, 20, 80, 40, 50, 15 };
            // or int[] ages = new int[2];
            // ages[0] = 1;
            // ages[1] = 2;

            // or int[] ages = new int[6]  { 10, 20, 30, 40, 50, 60 };

            // sorting array
            Array.Sort(ages);

            // reverse array
            Array.Reverse(ages);
            for (int i = 0; i < ages.Length; i++)
            {
                Console.WriteLine("i[" + i + "]" + "=" + ages[i]);
            }

            // 2- two dimention array

            string[,] rectangle = new string[2, 3];  // row * coulmns
            rectangle[0, 0]     = "mohamed";
            rectangle[0, 1]     = "abd";
            rectangle[0, 2]     = "algafour";
            rectangle[1, 0]     = "ahmed";
            rectangle[1, 1]     = rectangle[0, 0];
            rectangle[1, 2]     = "ali";

            for (int row = 0; row <= rectangle.GetUpperBound(0); row++)
            {
                for (int coulmn = 0; coulmn <= rectangle.GetUpperBound(1); coulmn++)
                {
                    Console.WriteLine(rectangle[row, coulmn]);
                }
            }

            // 3- array of array

            int[][] jagged = new int[3][];
            jagged[0] = new int[3] {
                1, 2, 3
            };
            jagged[1] = new int[2] {
                50, 60
            };
            jagged[2] = new int[5] {
                1, 2, 3, 4, 5
            };

            for (int outer = 0; outer < jagged.Length; outer++)
            {
                for (int inner = 0; inner < jagged[outer].Length; inner++)
                {
                    Console.Write(jagged[outer][inner] + ",");
                }
                Console.WriteLine();
            }


            // example of collections and workink ...

            // arraylist
            int[]     age = { 100, 200, 300 };
            ArrayList seq = new ArrayList();

            seq.Add(1);
            seq.Add('c');
            seq.InsertRange(1, age);
            seq.Insert(0, "hi");
            seq.Remove(100);
            seq.RemoveAt(0);
            foreach (var item in seq)
            {
                Console.WriteLine(item);
            }


            //sortedlist
            SortedList seq2 = new SortedList();

            seq2.Add("team A", 50);
            seq2.Add("team B", 50);
            seq2.Add("team C", 50);
            foreach (DictionaryEntry item in seq2)
            {
                Console.WriteLine(item.Key);
                Console.WriteLine(item.Value);
            }

            // stack
            Stack st = new Stack();

            st.Push("1");
            st.Push("10");
            st.Push("11");
            st.Push("12");
            st.Pop("1");
            st.Pop("10");
            st.Pop("11");
            st.Pop("12");

            //  Queue
            Queue q = new Queue();

            q.Enqueue(1);
            q.Enqueue(15);
            q.Enqueue(23);
            q.Enqueue(2);
        }
Ejemplo n.º 2
0
        // Main method.
        static void Main()
        {
            Console.Title = "Console App Core";  // Title of the console screen.

            // calling class with non static method.
            Human mohamed = new Human(); // ahmed object from human , calling with object.

            mohamed.add(10, 20);         // return 30.

            // calling class with static method.
            Human.sum(10, 20);  // return 30.
            // above code it printing in memory.


            // hear printing from memory to user interfsce.
            System.Console.WriteLine(Human.sum(10, 20)); // without system libarary.


            // Example for swaping varibles.

            int a = 10;
            int b = 20;

            // swap a = 20 , b = 10 without using any temp varaible.
            b = a;         // b = 10.
            a = b + b;     // a = 10 + 10 = 20.

            int x = 99;
            int y = 101;

            //swap x = 101 , y = 99 without using any temp varaible.
            x = x + y;     // x = 99 + 101 = 200.
            y = x - y;     // y = 200 - 101 = 99.
            x = x - y;     // x = 200 - 99 = 101.


            Childs childs = new Childs();  // object from childs  >> has a relationship.

            Console.WriteLine(childs.age);

            Store Cairo = new Store();

            Console.WriteLine(Cairo.NumberOfReminingProduct(20));      // 20 requested quntity  >> 80 all quntity

            Store Ismailia = new Store();

            Console.WriteLine(Ismailia.NumberOfReminingProduct(30));   // 30 requested quntity  >> 50 all quntity

            Store Alex = new Store();

            Console.WriteLine(Alex.NumberOfReminingProduct(50));      // 50 requested quntity  >> 0 all quntity


            //  Demo d = new Demo();  // proccess 1   >>  time 1  : time of object creation.
            //d.PrintMe();          // proccess 2   >>  time 2  : time of calling to method.


            // when class have constructor
            Demo dc = new Demo(); // only 1 proccess and 1 time.

            // object with constructor overloding
            Demo dco = new Demo(); // only 1 proccess and 1 time.



            MyClass m1 = new MyClass();
            // Console.WriteLine(m1.name);

            MyClass m2 = m1;

            m2.name = "reco2";
            Console.WriteLine(m1.name);
            Console.WriteLine(m2.name);


            Reco r = Reco.createObj();

            r.speak();

            utilits u        = new utilits("reco"); // object from class with overload constructor.
            string  username = "******";
            string  password = "******";

            // fore loop
            for (int i = 0; i < 100; i++) // strucur of for loop with condition and incriment.
            {
                if (i % 2 == 0)
                {
                    if (i <= 9)
                    {
                        Console.WriteLine("even number :  " + i);
                    }
                    else
                    {
                        Console.WriteLine("even number : " + i);
                    }
                }

                else
                {
                    Console.WriteLine("odd  number :  " + i);
                }
            }

            // while
            int index = 0;

            while (index < 10)
            {
                Console.WriteLine(index);
                index++;
            }

            // do while
            int val = 0;

            do
            {
                Console.WriteLine(val);
                val++;
            }while (val < 8);

            //foreach

            // inline if  , // ternary operator {dision making}.
            string answer = "good";
            string result = (answer == "good") ? "good job" : "bad job";

            Console.WriteLine(result);


            //if else

            if (username == "ahmed" && password == "123456")
            {
                Console.WriteLine("login success ... ");
            }

            else
            {
                Console.WriteLine("login faild ...");
            }

            //if elseif else
            if (username == "ahmed" && password == "123456")
            {
                Console.WriteLine("login success ... ");
            }

            else if (username == "ahmed" || password == "123456")
            {
                Console.WriteLine("login simi success .... ");
            }

            else
            {
                Console.WriteLine("login faild ... ");
            }

            //swich case comapre between value and value only  >>  like if else but cant using multi operators.
            int myAge = 20;

            switch (myAge)
            {
            case 20:
                Console.WriteLine("same age");
                break;      // end proccess

            case 30:
                Console.WriteLine("not match");
                break;      // end proccess

            default:
                Console.WriteLine("plz chose");     //like else
                break;
            }
        }