public void Awake()
 {
     if (!instance)
     {
         instance = this;
     }
 }
Esempio n. 2
0
        public static void Example01()
        {
            //simplest class example
            YourClassName ycn = new YourClassName();

            Console.WriteLine("YourClassName class created");

            //field modifiers example
            FieldModifiersClass fmc = new FieldModifiersClass();

            Console.WriteLine("FieldModifiersClass class created");

            //methods and constructor examples
            Octopus o = new Octopus("zvecarka");             // Call constructor

            Console.WriteLine("Octopus class created: " + o.Age);
            o.WriteCubes();
            (string name, int age) = o;                     // Call deconstructor
            Console.WriteLine("Octopus class deconstructed age: " + o.Age);
            Console.WriteLine("Octopus class deconstructed name: " + name);
            Console.WriteLine("Octopus class deconstructed age: " + age);
            age = 22;
            Console.WriteLine("Octopus class deconstructed age changed?: " + o.Age);

            //object initializers examples
            Bunny b1 = new Bunny {
                Name = "Bo", LikesCarrots = true, LikesHumans = false
            };

            Console.WriteLine($"Bunny1 {b1.Name}, {b1.LikesCarrots}, {b1.LikesHumans}");
            Bunny b2 = new Bunny("Bo")
            {
                LikesCarrots = true, LikesHumans = false
            };

            Console.WriteLine($"Bunny2 {b2.Name}, {b2.LikesCarrots}, {b2.LikesHumans}");
            Bunny b3 = new Bunny(name: "Bo", likesCarrots: true);

            Console.WriteLine($"Bunny3 {b3.Name}, {b3.LikesCarrots}, {b3.LikesHumans}");

            //properties examples
            Stock msft = new Stock();

            msft.CurrentPrice  = 30;
            msft.CurrentPrice -= 3;
            Console.WriteLine("Current price is = " + msft.CurrentPrice);
            msft.SharesOwned = 100;
            Console.WriteLine("My stock worth is = " + msft.Worth);
            msft.Worth3 = 27M;
            Console.WriteLine("Current shares owned is = " + msft.SharesOwned);
            Console.WriteLine("CurrentPrice2 property = " + msft.CurrentPrice2);
            Console.WriteLine("CurrentPrice3 property = " + msft.CurrentPrice3);

            //indexers examples
            Sentence s = new Sentence();

            Console.WriteLine(s[3]);       // fox
            s[3] = "kangaroo";
            Console.WriteLine(s[3]);       // kangaroo

            //partial types example
            PaymentForm pf = new PaymentForm();

            pf.Field1 = 23;
            Console.WriteLine("Partial types example = " + pf.Field1);
        }