Daniel
Daniel

Reputation: 33

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 availbel to all the classes outside the form?

Thanks

Daniel

Upvotes: 1

Views: 107

Answers (4)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171411

You could persist the form input to a database and then access through the repository pattern, for example.

Upvotes: 1

Pabuc
Pabuc

Reputation: 5638

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.

Upvotes: 0

kemiller2002
kemiller2002

Reputation: 115488

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.

Upvotes: 1

Klaus Byskov Pedersen
Klaus Byskov Pedersen

Reputation: 120937

Encapsulate the data in a class and pass an instance of that class from your form to the other classes.

Upvotes: 4

Related Questions