Related Articles

Back to Latest Articles

C# Basics – Constructors – Part 12

We explore how constructors work and for what we might need to use them.

Andraz Krzisnik
C# Basics – Constructors – Part...


Sometimes we want to create an object and set some predetermined state to it. Basically, you would pass the properties’ values as an argument to an object when you are creating it. Whenever we are creating a constructor, there is something important to keep in mind, we need to set it’s name exactly the same as the name of the class it’s in.

We also can’t call it just anywhere like functions. We can only call a constructor with a new keyword in the beginning.

And when we would use it, we’d write:

Download Examples Next Chapter
Show Comments (0)


Related Articles

C# Basics

C# Basics – Object Arrays – Part 13

Object Arrays We already mentioned before, that when we create a class we create an object with custom data type. So, as you can see, like strings, integers and other data types,...

Posted on by Andraz Krzisnik
C# Basics

C# Basics – Exception Handling Statements – Part 9

Exception Handling Statements Sometimes, there comes a situation that where our code might crash. We can handle these kind of situations with exception handling statements. By...

Posted on by Andraz Krzisnik