예제 #1
0
        static void Main(string[] args)
        {
            Car car;

            car = new Car("Red");
            Console.WriteLine(car.Describe());

            car = new Car("Green");
            Console.WriteLine(car.Describe());

            Console.ReadLine();
        }
예제 #2
0
        // the params modifier
        // arbitrary number of params in an array

        // long way to call it:
        // GreetPersons(new string[] { "John", "Jane", "Tarzan" });

        // better way with params keyword
        // static void GreetPersons(params string[] names) { }
        // GreetPersons("John", "Jane", "Tarzan");
        // params keyword also makes params optional (0 params)
        // can mix optional and required params
        // params keyword has to come last
        // static void GreetPersons(int someUnusedParameter, params string[] names)

        // static:
        // method should be accessible without instantiating the class (aka a class method in Ruby)
        // Main is the entry point:
        // first code to be executed
        static void Main(string[] args)
        {
            // Variable
            // declare variable with type car
            Car car;

            // new instance of it with parameter "Red"
            car = new Car("Red");
            Console.WriteLine(car.Describe());

            // another instance of same class
            car = new Car("Green");
            Console.WriteLine(car.Describe());

            // reads the next line of characters from the standard input stream
            // returns String or null
            Console.ReadLine();
            // compare to Console.Read();
            // reads the next character from the standard input stream
            // returns Int32 or -1 if none

            // this ReadLine is a trick to keep the window from closing until prompted
        }
예제 #3
0
        static void Main(string[] args)
        {
            string username = "******";
            string password = "******";

            Console.WriteLine("Hello " + username +", your password is :" + password);
            Console.WriteLine("New Password please:");
            password = Console.ReadLine();
            Console.WriteLine("Hello " + username + ", your new password is :" + password);
            Console.ReadLine();

            Car car;
            car = new Car("Red");
            Console.WriteLine(car.Describe());
            Console.WriteLine("The car getter method is exposed for color: " + car.Color);
            car.Color = "purple";
            Console.WriteLine("The car setter method is exposed for color: " + car.Color);

            Car car2 = new Car("Green");
            Console.WriteLine(car2.Describe());
            Console.ReadLine();

            GreetPersons(0);
            GreetPersons(25, "John", "Jane", "Tarzan");
            Console.ReadKey();

            int number1;
            do
            {
                Console.WriteLine("Please enter a number(1-10):");
                number1 = int.Parse(Console.ReadLine());
                if ((number1 > 0) && (number1 < 11))
                    Console.WriteLine("Good job!");
                else
                    Console.WriteLine("Out of range.. boo");

            } while ((number1 < 1) || (number1 > 10));

            int result = AddNumbers(number1);
            Console.WriteLine("Adding ?? to your number: " + result);
            Console.ReadLine();

            ArrayList list = new ArrayList();
            list.Add("John Doe");
            list.Add("Jane Doe");
            list.Add("Someone Else");

            foreach(string name in list)
                Console.WriteLine(name);

            Console.ReadLine();

            //Class with Public methods
            MyClass cls  = new MyClass();
            Console.Write("Write a number: ");
            long a= Convert.ToInt64(Console.ReadLine()); // a is the number given by the user
            long av = cls.volteado(a);
            bool isTrue = cls.siprimo(a);
            bool isavTrue = cls.siprimo(av);
            Console.WriteLine("a: " + a + "av: " + av);
            if (isTrue == false && isavTrue == false)
                Console.WriteLine("Both original and swapped numbers are prime.");
            else
                Console.WriteLine("One of the numbers isnt prime.");
            Console.ReadLine();

            Console.WriteLine("Do you enjoy C# ? (yes/no/maybe)");
            string input = Console.ReadLine();
            switch(input.ToLower())
            {
                case "yes":
                case "maybe":
                    Console.WriteLine("Great!");
                    break;
                case "no":
                    Console.WriteLine("Too bad!");
                    break;
                default:
                    Console.WriteLine("I'm sorry, I don't understand that!");
                    break;
            }

            Console.ReadLine();
        }