From the course: C# Essential Training 1: Types and Control Flow

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Creating static classes

Creating static classes

- [Narrator] One last type I'd like to talk about is the notion of a static class. We've had instance classes with instant state. We can also have static classes. I come out here and add a class. I'm going to call it Constance. Let's see, yes. We've got a bunch of stuff here that will clean up a little bit, and I'm not going to make that internal, but I am going to make it static. What's special about a static class. Well, I'm really defining a class that I'm going to be able to use without creating an instance of it. In fact, I try and put a constructor on here. I'm going to get a warning telling me I can't create instances of a static class. What I can do is make a static constructor. And what that means is, when this is first used, when it's first initialized, this constructor would get called. Notice, there's no public private accessories on it. It's going to get called. You can use static constructors on instance classes. So if you want to have some constructor logic that happens…

Contents