How to Write and Retrieve Internal Class Properties When Inheriting Internal Class

Asked 1 years ago, Updated 1 years ago, 329 views

If the parent class has an internal class,
I would like to know how to read and write the properties of the internal class from the inheritance destination.

public class MainClass:ClassA{
   ClassAa = new ClassA();
   a. AAA = "OK";
   // a.classB.BBB??// ← I want to read and write this, but I can't access it
}

public class ClassA {
   public string AAA {get;set;}

   public class ClassB{
      public string BBB {get;set;}
   }
}

Thank you for your cooperation.

c#

2022-12-20 13:20

1 Answers

Instancing ClassA does not mean that ClassB is instantiated.
To use it like the code presented, you must instantiate and publish ClassB as soon as ClassA is instantiated.

public class ClassA
{
    public string AAA {get;set;}
    publicClassBclassB{get;} = newClassB();

    public class ClassB
    {
        public string BBB {get;set;}
    }
}


2022-12-21 20:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.