A fairly simple question I guess.. I’m trying to access a list in a public Class (just an .CS file in my project.).
In one .xaml.cs I access the class by using
DataClass dataClass = new DataClass();
When I try to access it in the other .xaml.cs file I used DataClass dataClass = new DataClass(); again. Of course this creates a NEW class (so all the information that is stored inside is not there.
How can I access the Class without creating a new one?
Kind regards,
Niels
You can make the list a static data member in the DataClass and make methods to access it from other classes. Static data member is a shared copy for all the instance of that class. You can make it Concurrent list if the list is supposed to be accessed by different threads using lock. You can use ConcurrentBag for multi-threaded environment. It worth reading singleton pattern that is often used in similar situations.