Sharing variables or properties between classes?

lukas9669

Member
Joined
Feb 7, 2022
Messages
9
Programming Experience
1-3
Is there a way to share variables or properties between to classes?
For example I have a blazor web app with 2 pages and 2 partial classes. How can I share the variable A from class 1 with class 2?
Is there a way to do this?
 
Normally you would expose something that you want to be shared as a public property. Then you access that property using an instance of that class.

So in your case above, you would create an instance of a class that exposes your variable A as a property, and then you would pass references of that class instance to your two code behind classes. This is called dependency injection.
 
Last edited:
Back
Top Bottom