Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Use get to display the property and set to set a value of the property in the code, if u don’t use

set then
the property will only be read only and u cant set a value to it and then to display the property you will
have to use curly brackets in front of get and return another variable

U can also do statements with set like

Creating exceptions and throwing them is to basically create an error in the code if an event happens
U can throw an exception multiple times by

To add members of one class to another class, you can make it inherit them by adding a colon and name
of class when making new class like this

(ignore the word public)

This inherits all the non-private members of MyClass to MySecondClass

The class that is inherited from is called the base class and the class that inherits is called the derived
class

Blue is base, not blue is derived, note how u have to do base.Age to access that member in derived class
from base class
When you use the access modifier “protected” instead of “public”, it only allows it to be used in either
the base class or its derived classes but not elsewhere.

Can only be accessed in the class it is created in and in the class that is derived from it
If you want to override one method with another method then firstly use same name for both methods
but in the original method (Method A) you’ll use public void and in the method you want to override
with (Method B) you use ‘public new void’ and here Method B will override Method A, the keyword new
is used for overriding. (this is useful when you can not access a class for example if it is inside of a dll)

You can also use the override keyword but for this to be used, Method A must be virtual so ‘public
virtual void’ and Method B must be ‘override void’, and both Methods must have the same name too.

These are 2 ways of overriding.

You might also like