getter and setter for class in class c#

前端 未结 5 1816
攒了一身酷
攒了一身酷 2021-02-19 01:48

Assuming we have a class InnerClass with attributes and getter/setter. We also have a class OuterClass containing the InnerClass.

e.g.

class InnerClass
{         


        
5条回答
  •  我在风中等你
    2021-02-19 02:34

    It depends on how the inner class should work. The outer class might need to "own" the inner class, in which case:

    public InnerClass InnerClass{
      get{ return innerClass; }
      set{ innerClass.CopyFrom(value); /* Pseudo method call */ }
    }
    

    By doing it this way, you prevent outside code from manipulating the instance unless explicitly through OuterClass..

提交回复
热议问题