Link to home
Start Free TrialLog in
Avatar of kalyangkm
kalyangkmFlag for United States of America

asked on

Create a static class with List of accounts that acts as a data store.

how to Create a static class with List of accounts that acts as a data store and how to use it in c#
ASKER CERTIFIED SOLUTION
Avatar of Misha
Misha
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To use it you use the class name, no need to create an object of that type
MyAccountXXXX = RepositoryClass.Accounts...  (replace the dots with property, function or whatever it is you want)
You don't. There is no real use-case for a static class. Code reuse and testability speaks against it.

Take a look at the Repository pattern. And Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application (9 of 10).

Why do you think, you need a static class in this case?
I completely agree to ste5an. It is not a good idea to use static classes here.
read more at MS site:
Static Classes and Static Class Members (C# Programming Guide)

You may also consider a Singleton pattern.
I strongly disagree with the marked post as answer. It uses uninitialized members. It does not encapsulate the internals. Object lifetime is not clear.
@Ste5an and Anarki.  Whether static class is suitable or not is irrelevant.  The asker wanted to know how to use a static class.  Admittedly the accepted comment only partially answers the question and even that in a poor way but it may well have been enough to help the asker.