Exemplo n.º 1
0
        private static void enums()
        {
            //enums are handy when we have a list of values and we want to pick one from it
            //enums are types (we can declare variables, properties, parameters, return values and so on)
            ConsoleColor oldColor = Console.ForegroundColor;

            //they are value types:
            //we copied the value of ForegroundColor into oldColor but if we change one of the two, the other remains unchanged
            Console.ForegroundColor = ConsoleColor.Red;
            System.Console.WriteLine("I'M SEEING RED!");
            System.Console.WriteLine(oldColor); //still gray
            //we can only assign values picked up from the list, not simple strings or numbers
            //Console.ForegroundColor = "Red"; //does not compile
            //Console.ForegroundColor = 255; //does not compile
            Console.ForegroundColor = ConsoleColor.Cyan; //compiles
            Console.ForegroundColor = oldColor;

            //we can also define our own enums and use them
            //(you can find the definition in the file Enumerations.cs)
            ItalianDays favoriteDay = ItalianDays.Sabato;

            System.Console.WriteLine(favoriteDay); //Sabato
        }
Exemplo n.º 2
0
        private static void M01()
        {
            //type name;
            //name = expression;

            //type name = expression;

            //value types ==> struct, enum
            //reference types ==> class, arrays, delegates

            int a = 5; //inline memory

            //a = null;

            string s1 = null;

            //Nullable<int> a2 = 5;


            long l = long.MaxValue;

            a = (int)l;

            //bool b = (bool)a;

            //bool b = 1;


            a = 3;

            a = 5;
            int b = 10;

            b = a++;

            b = ++a;

            b = a > 5 ? 10 : 20;

            char c1 = 'a';

            //c1 = "c";


            //string s1 = 'asdg';

            s1 = "asdg";    //

            s1 = s1 + "aa"; //asdgaa

            StringBuilder builder = new StringBuilder();

            builder.Append("aa");
            builder.Append("aa");
            builder.Append("aa");

            string s2 = builder.ToString();

            s2.Trim();

            s1 = a.ToString();

            s1 = "5";

            if (int.TryParse(s1, out a))
            {
            }

            //enum

            Method02();

            Point p = new Point(3, 4);

            Console.BackgroundColor = ConsoleColor.Yellow;

            ItalianDays day = ItalianDays.Lunedi;

            ItalianDays day2 = day;

            day = ItalianDays.Martedi;


            int d = (int)day;

            Console.WriteLine(day);

            Person simo = new Person(1, "Simo", "Cola");

            simo.Id          = 5;
            simo.Name        = "Simona";
            simo.Surname     = "Colapicchioni";
            simo.FavoriteDay = ItalianDays.Mercoledi;

            simo.DoSomething();

            Console.WriteLine("What's the id?");

            simo.Id = int.Parse(Console.ReadLine());
        }