Monday, July 28, 2014

Understanding this Reference usage in between two different classes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps
{

    class CallingAnotherClassMethod
    {
        private string[] items = new string[5];
        public int k { getset; }
        public int i { getset; }
        public int j { getset; }
        //public int i=5,j=12;

        public void CallingMethod()
        {
            k = 10;
            j = -7;
            i = 12;
            //Here this is used to pass the fields like k,i,j to the another class methods.
            Console.WriteLine(ObjectReferingToCallingMethod.objectCreationOfCallingMethod(this));
            //Also we are calling Method with class name because the method is static in the below class.
        }

    }

    class ObjectReferingToCallingMethod
    {
        public static int objectCreationOfCallingMethod(CallingAnotherClassMethod cl)
        {
            return 10 * cl.k*cl.i*cl.j;
        }
    }
    class UnderstandingThisReference
    {
        public static void Main()
        {
            CallingAnotherClassMethod obj = new CallingAnotherClassMethod();
            obj.CallingMethod();
        }
    }
}

No comments:

Post a Comment