示例#1
0
        static void Main(string[] args)
        {
            ClassA myObject = new ClassA();

            Console.WriteLine($"myObject.State = {myObject.State}");
            ClassA.ClassB myOtherObject = new ClassA.ClassB();
            myOtherObject.SetPrivateState(myObject, 999);
            Console.WriteLine($"myObject.State = {myObject.State}");
        }
示例#2
0
 static void Main(string[] args)
 {
     ClassA myObject = new ClassA();
      Console.WriteLine("myObject.State = {0}", myObject.State);
      ClassA.ClassB myOtherObject = new ClassA.ClassB();
      myOtherObject.SetPrivateState(myObject, 999);
      Console.WriteLine("myObject.State = {0}", myObject.State);
      Console.ReadKey();
 }
示例#3
0
        static void Main(string[] args)
        {
            var myObject = new ClassA();

            WriteLine($"myObject.State = {myObject.State}");
            var myOtherObject = new ClassA.ClassB();

            myOtherObject.SetPrivateState(myObject, 999);
            WriteLine($"myObject.State = {myObject.State}");
            ReadKey();
        }
示例#4
0
        static void Main(string[] args)
        {
            ClassA myObject = new ClassA();

            WriteLine($"myObject.State = {myObject.State}");

            // Create an instance of the nested class, and use it to set the read-only State
            // property of the outer class. Note the hierarchical syntax required to define
            // and instantiate the nested class.
            ClassA.ClassB myOtherObject = new ClassA.ClassB();
            myOtherObject.SetPrivateState(myObject, 999);
            WriteLine($"myObject.State = {myObject.State}");
            ReadKey();
        }
示例#5
0
        static void Main(string[] args)
        {
            // Create main class, show current val of state
            ClassA myObject = new ClassA();

            WriteLine($"myObject.State = {myObject.State}");

            // Create the subclass, call its method and pass the main class
            ClassA.ClassB myOtherObject = new ClassA.ClassB(); // Interessant dat een subclass van een object toegang heeft tot de private members van een ander object
            myOtherObject.SetPrivateState(myObject, 999);

            // Show the current val of state
            WriteLine($"myObject.State = {myObject.State}");
        }