Home > Net >  C # will structure used in reference to the class instance
C # will structure used in reference to the class instance

Time:12-08

Please everyone a great god, and now I have a structure body, want to call changes in reference to a class instance, but I learned right now, value types of data, to reference use only ref method, but this way not only can be used in a function? How can I put this reference to an instance of a class to use? For example: I have A struct A, an A new comes out, and then assign A value, and A class B, instance of A B, now want to have A reference to B, B as an instance of A global variable, how to do? I have tried to use the public b (ref A A) way to introduce, but this can only be quoted in the constructor of A, b

CodePudding user response:

For class B members of A static public static aa {get; set; }=new A ();

CodePudding user response:

No, this is exclusive of the class B, what I want is the external incoming A, only this one instance to B in general,

CodePudding user response:

refer to the second floor weixin_46551080 response:
no, this is exclusive of class B, what I want is outside of the incoming A, only to gm in this one instance, B

Then use protect static aa {get; set; }=new A ();

CodePudding user response:


refer to the second floor weixin_46551080 response:
no, this is exclusive of class B, what I want is outside of the incoming A, only to gm in this one instance, B

You change the description way to describe your problem, the A, B to you real object name, sense, so that better communication.

CodePudding user response:

refer to the second floor weixin_46551080 response:
no, this is exclusive of class B, what I want is outside of the incoming A, only to gm in this one instance, B

Then it is good to add A property not B directly,
B.A before B run call=a;
  •  Tags:  
  • C#
  • Related