Static classes | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Static classes

Can someone explain to me the of use static classes with an example please.

24th Dec 2018, 6:06 PM
Jahmai Jones
Jahmai Jones - avatar
1 Resposta
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.
24th Dec 2018, 11:33 PM
John
John - avatar