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 - C# Tutorial
From the course: C# Essential Training 1: Types and Control Flow
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Understanding classes, structs, and records7m
-
(Locked)
Defining constructors7m 6s
-
(Locked)
Object initialization6m 4s
-
(Locked)
Initialize only properties4m 59s
-
(Locked)
Cloning and copying objects9m 32s
-
(Locked)
Equality comparisons5m 27s
-
(Locked)
Defining abstract classes7m 52s
-
(Locked)
Creating static classes5m 18s
-
(Locked)
Solution: Expressing equality1m 5s
-
-
-
-
-
-