/// <summary>
        /// When a class member includes a static modifier, the members is called as static members.
        /// When NO static modifier, then members is called as non-static or instance members.
        /// Static members can be invoked usign class name where as instance members are invoked using instance of the class.
        ///
        /// An instance member belongs to specific instance of a class. If i create 3 instance(object) of a class i will have 3 set of instance member in memory.
        /// Where as there will be only one copy of static member. no matter how many times instance of class is created.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            /*
             * Since here when we call c1.CalculateArea() or c2.CalculateArea() every time the value of pi is going to be constant.
             * And with every object created it will take memory since it is instance member.
             */
            Circel c1    = new Circel(4);
            float  area1 = c1.CalculateArea();

            Console.WriteLine("Area of circle is {0}.", area1);

            Circel c2    = new Circel(6);
            float  area2 = c2.CalculateArea();

            Console.WriteLine("Area of circle is {0}.", area2);

            /*
             * Now below codes are similar to above but this will less consume memory because its pi value is created as static member.
             */
            Circel2 c3    = new Circel2(4);
            float   area3 = c3.CalculateArea2();

            Console.WriteLine("Area of circle is {0}.", area3);

            Circel2 c4    = new Circel2(6);
            float   area4 = c4.CalculateArea2();

            Console.WriteLine("Area of circle is {0}.", area4);


            Console.ReadKey();
        }
Example #2
0
        /// <summary>
        /// When a class member includes a static modifier, the members is called as static members.
        /// When NO static modifier, then members is called as non-static or instance members.
        /// Static members can be invoked usign class name where as instance members are invoked using instance of the class.
        /// 
        /// An instance member belongs to specific instance of a class. If i create 3 instance(object) of a class i will have 3 set of instance member in memory.
        /// Where as there will be only one copy of static member. no matter how many times instance of class is created.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            /*
             Since here when we call c1.CalculateArea() or c2.CalculateArea() every time the value of pi is going to be constant.
             * And with every object created it will take memory since it is instance member.
             */
            Circel c1 = new Circel(4);
            float area1 = c1.CalculateArea();
            Console.WriteLine("Area of circle is {0}.", area1);

            Circel c2 = new Circel(6);
            float area2 = c2.CalculateArea();
            Console.WriteLine("Area of circle is {0}.", area2);

            /*
             Now below codes are similar to above but this will less consume memory because its pi value is created as static member.
             */
            Circel2 c3 = new Circel2(4);
            float area3 = c3.CalculateArea2();
            Console.WriteLine("Area of circle is {0}.", area3);

            Circel2 c4 = new Circel2(6);
            float area4 = c4.CalculateArea2();
            Console.WriteLine("Area of circle is {0}.", area4);

            Console.ReadKey();
        }