0
Static classes
Can someone explain to me the of use static classes with an example please.
1 Odpowiedź
0
static classes cannot be instantiated, they are single instance, and globally callable.
public class Dog
{
public string Name { get; set; }
public int Age {get; set;}
}
public static class DogManager
{
private List<Dog> _dogs = new ...;
public void AddDog(Dog dog)
{
if(dog != null)
_dogs.AddDog(dog);
}
public list<Dog> GetDogs => _dogs;
}
// the code is just an example and should
have used interfaces to maintain extensibility.
// use
DogManager.AddDog(new Dog(){ Name = "Dave" });
... this shows the use of a static class.. im at work and don't have time to explain any further.