From the course: C# Best Practices for Developers
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Using constructors - C# Tutorial
From the course: C# Best Practices for Developers
Using constructors
- [Instructor] Hi everyone. I'd like to talk about constructors and the best ways to use them. Now, a constructor can be created using a snippet that Visual Studio provides. Spelt out as ctor, and when I hit tab tab, it immediately creates a constructor for our Actor class. Now, a couple of points about constructors that I'd like to make is that they're a method in a class that is executed when an instance of the class is created. Now, it has the same name of the class as you can see here on line 11. And this particular constructor is called a default constructor and it has no parameters. And it's actually not required for you to put it in but when you do not C# will create an implicit constructor for you. Now we can also have a parametrized constructor where you can pass in parameters. Lets go ahead and create one. And lets say I want to pass in an actor name. Well, lets go ahead and create a property for that. And I'll use another code snippet called propfull. And I want to be…
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
-
-
-
-
Project setup overview1m 13s
-
Set up the business layer2m 18s
-
Running a unit test3m 13s
-
Class naming conventions and standards5m 2s
-
Field and property naming conventions4m 22s
-
Using constructors3m 9s
-
Unit testing constructors4m 30s
-
Namespaces2m 48s
-
Static classes3m 10s
-
Unit testing static classes4m 20s
-
Using a singleton2m 6s
-
-
-
-
-