I have made the Graph class, and i want to simulate a distribution network. The Graph works 100%. But, i want to use that same struct/class in all my application! For example: I have Form1 that shows the simulation, but i want to insert Nodes (for example) but i want to do it in Form2! Since the data is always in the same class, i could make my Graph instance global but C# does not take global variables. So, how would i solve this? Any ideas? Thank you!
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Make a static class. The variables that need global access, put them inside that class.
Even better idea would be to use Singleton objects to represent globally accessible objects.
Give the forms a reference to the Graph in their constructor.
Then both forms are working with the same graph.
C# has static fields for this. You can use SIngleton pattern in conjunction with static field. But don't forget that misusage of application-wide objects can bring down your design.
Make your Graph instance a public static member of a static class and for all practical purposes you have your global.
Take a look at the Singleton pattern for one possible approach to having a common object:
Singleton Pattern