Share variable between multiple classes

前端 未结 5 1553
囚心锁ツ
囚心锁ツ 2021-01-06 13:11

If i have 3 classes, lets say: Mainclass, ChildClass, OtherChild.

MainClass()
{
     ChildClass cc = new ChildClass();
     OtherChild oc = new OtherChild();         


        
5条回答
  •  天涯浪人
    2021-01-06 14:04

    Create a constructor for OtherChild that takes an instance of ChildClass, or just the name property if that is all you need.

    public class OtherChild
    {
        ChildClass _cc;
    
        public OtherChild(ChildClass cc)
        {
            this._cc = cc;
        }
    }
    

提交回复
热议问题