Static classes are used when you are not going to create objects. You get one “instance” of this class - you cannot do things like:
MyStaticClass m = new MyStaticClass(); m.SomeFunc();
when you have a static class. Instead, you will use it using the class name. Sort of:
MyStaticClass.SomeFunc();
What will you use to track each Customer object? You can use some kind of collection to store them. Of course, in a real system for storing data there may be some kind of emphasis, probably a database. But you could just do something like:
IEnumerable<Customer> Customers = new List<Customer>();
And then add your customers to this list.
Customers.Add(new Customer() { ... });
Back to the question about static methods ...
So, the point here is that you are not going to refer to instance members in the static method, so you will not use static methods to update a specific client address. Assuming your Customer class is as follows:
public class Customer { public string Address { get; set; } }
You cannot use a static method like
public static void SetAddress()
because each Client (presumably) has a different address. You cannot access the client address there because it is not static. Get it? Instead, you should use a static method if you want to do something that does not need to be processed with instance data. I use static methods for functions such as utility functions.
public static double ComputeSomething(double someVal) { ... }
Here, the ComputeSomething function can be called by anyone who:
var result = MyStaticClass.ComputeSomething(3.15);
The conclusion here is that static classes are not used to create objects, but they are really used as a convenient container for storing functions. Static functions are those that can be in a non-static class, but cannot access any instance data.
One place where the static function will be used will be for the Singleton template. You make the constructor non-public so that people cannot call it, and instead provide a static method for the class to return a single instance of the class. Sort of:
public class MySingleton { private static MySingleton instance; private MySingleton() {} public static MySingleton Instance { get { if (instance == null) { instance = new MySingleton(); } return instance; } } }