示例#1
0
        static void Main(string[] args)
        {
            //pattern
            printPattern();

            // swap two numbers without using the third number
            int firstNumber = 10, secondNumber = 5;

            firstNumber  = firstNumber + secondNumber; // 15
            secondNumber = firstNumber - secondNumber; //15 - 5 = 10;
            firstNumber  = firstNumber - secondNumber;

            Console.WriteLine("First Number is " + firstNumber + " Second Number is" + secondNumber);

            // Palindrome Function
            Console.WriteLine("Enter number to check if it is palindrome or not");
            int toCheckPalindrome = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine(IsPalindrome(toCheckPalindrome));

            //Abstract Class Implementation
            DerivedClass derivedObj = new DerivedClass();

            derivedObj.TestFunction();


            //Interface
            Car carObj = new Car();

            carObj.Brake();
            carObj.Move();


            //Constructors Example
            ConstructorsExample constructorObj1 = new ConstructorsExample();
            ConstructorsExample constructorObj2 = new ConstructorsExample(10, 5);
            ConstructorsExample constructorObj3 = new ConstructorsExample(constructorObj2);

            //static Constructor
            StaticClass staticObj = new StaticClass();

            Console.WriteLine("ConstructorObj3's firstnumber is " + constructorObj3.GetFirstNumber() + " and Second is " + constructorObj3.GetFirstNumber());

            //exception Handling
            ExceptionHandlingExample exceptionObj = new ExceptionHandlingExample();

            exceptionObj.DivideByZero();

            //will throw an exception if age is less then 18
            exceptionObj.ThrowException(20);

            //Get reverse String
            string str = "Himalya";

            Console.WriteLine("Reversed String is " + GetReverseString(str));


            //To check if 3 is present in a number
            if (ContainsInt(143) == true)
            {
                Console.WriteLine("Yes 3 is Present");
            }
            else
            {
                Console.WriteLine("No 3 is not present");
            }

            //Pointers
            createPointers();

            //
            int[] arr = { 15, 16, 17, 18 };

            arr = ReverseArray(arr);

            Console.WriteLine("Reversed Array");

            foreach (var element in arr)
            {
                Console.WriteLine(element);
            }
        }
 public ConstructorsExample(ConstructorsExample constructorObject)
 {
     this.firstNumber  = constructorObject.firstNumber;
     this.secondNumber = constructorObject.secondNumber;
 }