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#
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do you what to know about static calss?
For example, you can use this code.
	public static class RepositoryClass
		public static List<Account> Accounts;
	public class Account
		public string AccountName { get; set; }

Open in new window

Else if you waте do something from Accounts in ASP Net, please explain.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
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)
ste5anSenior DeveloperCommented:
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?
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

anarki_jimbelSenior DeveloperCommented:
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.
ste5anSenior DeveloperCommented:
I strongly disagree with the marked post as answer. It uses uninitialized members. It does not encapsulate the internals. Object lifetime is not clear.
AndyAinscowFreelance programmer / ConsultantCommented:
@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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.