Fixed typos, punctuation (#20666)
Also changed class "created" to "instantiated". Classes don't get created, objects get created.
This commit is contained in:
@ -3,7 +3,7 @@ title: Class
|
|||||||
---
|
---
|
||||||
## Class
|
## Class
|
||||||
|
|
||||||
A class in C# is defined as a reference type. In order to instatiate a variable of with a reference type you must specify the `new` keyword, else the variable will have the default value of `null`. See below for an example.
|
A class in C# is defined as a reference type. In order to instatiate a variable of a reference type you must use the `new` keyword, else the variable will have the default value of `null`. See below for an example.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// The value of variableOne is null at this point.
|
// The value of variableOne is null at this point.
|
||||||
@ -12,12 +12,12 @@ NewClass variableOne;
|
|||||||
// Now the value of variableOne will be an instance of the class NewClass
|
// Now the value of variableOne will be an instance of the class NewClass
|
||||||
variableOne = new NewClass();
|
variableOne = new NewClass();
|
||||||
```
|
```
|
||||||
At runtime when the class is created enough memory is allocated onto the heap for that specific instance of the class that the variable holds.
|
At runtime, when the class is instantiated, enough memory is allocated onto the heap for that specific instance of the class that the variable holds.
|
||||||
|
|
||||||
#### Creating Classes
|
#### Creating Classes
|
||||||
To create a class in C# we need to use the `class` keyword followed by a unique identifier.
|
To create a class in C# we need to use the `class` keyword followed by a unique identifier.
|
||||||
|
|
||||||
Like other languages, C# creates a default constructor that accepts no parameters. We can also specify our own constructor if we need to take in special parameters or have custom initlization steps in our constructor.
|
Like other languages, C# creates a default constructor that accepts no parameters. We can also specify our own constructor if we need to take in special parameters or have custom initialization steps in our constructor.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public class NewClass
|
public class NewClass
|
||||||
@ -29,7 +29,7 @@ public class NewClass
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
A class is a prototype or blueprint from which objects are created. In C#, the class is defined by using the keyword class. A class is used to combine together some methods, properties, fields, events, and delegates into a single unit. A class may contain nested classes too.
|
A class is a prototype or blueprint from which objects are created. In C#, the class is defined by using the keyword `class`. A class is used to combine together some methods, properties, fields, events, and delegates into a single unit. A class may contain nested classes too.
|
||||||
#### Example: Consider the case of Employee Class below:
|
#### Example: Consider the case of Employee Class below:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
|
Reference in New Issue
Block a user