C# Form Question
I have written a App that uses a simple form to collect some data from the user. What is the easiest way of making this data ava开发者_Go百科ilbel to all the classes outside the form?
Thanks
Daniel
Encapsulate the data in a class and pass an instance of that class from your form to the other classes.
The simplest was I can think of (although you have to be careful) is to create a static class with static public variables. Set those variables from the form data, and everything else can access it. You don't have data persistence, and you have to be careful about other classes updating it, but it will expose the values to all other classes in the program.
You could persist the form input to a database and then access through the repository pattern, for example.
I'd suggest keeping it in a xml file on users computer. That way, it would be very hard to change the data unless you change the xml again.
精彩评论