The car class has three fields and a constructor.
In the main program, a car object is instantiated and the parameters for the fields are passed in.
The console is used to show these values.
The quote class contains two methods.
Sartre() is an instance method and Wittgenstein() is a static method.
They are both void because the methods do not return a value.
An instance of the quote class is created and then the method is called on that instance.
The static method doesn't need to be called on an instance of the class.
The console displays the contents of the method: quotes.
The MathOps class contains
Multiple methods can have the same name as long as the number and/or type of parameters are different.
A method signature is a unique identification of a method for the C# compiler.
The signature consists of a method name and the type and kind (value, reference, or output) of each of its formal parameters.
Method signature does not include the return type.
In this example there is a base class (Author) and a derived class (Book).
The Book class inherits from the Author class.
This means that the Book class (derived class) can access the fields, proprties and methods defined in Author.
The console shows that an instance of the Book class can access the name field defined in the Author class.
Six frog objects are created with different tongue lengths.
The GetAverageTongueLength static method is called and the array is passed in.
(4 + 3 + 6 + 2 + 4 + 5) / 6
24 / 6 = The average legth is 4.
This example is an abstract base class.
For an abstract property or method, every derived class must overide it.
The boolean property UnihemisphericSleep has a protected set accessor.
This means that code inside the class or in it's derrived classes can access it.
Note that the property NoOfEyes is not abstract which means it doesn't need to be defined in the derrived classes yet instances of derrived classes like dog and dolphin still have this property.
Interface can contain declarations of method, properties, indexers, and events.
Interface cannot include private, protected, or internal members.
All the members are public by default.
Interface cannot contain fields, and auto-implemented properties.
Classes can have multiple interfaces, but classes cannot inherit multiple classes.
Classes inheriting from more than one class is known as multiple-inheritance.
C# does not allow multiple-inheritance
Below shows an example of an Interface (IPikachu.cs).
If the number is a multiple of 3 it is replaced with the string "FIZZ".
If the number is a multiple of 5 it is replaced with the string "BUZZ".
If the number is a multiple of 3 AND 5, it is replaced with the string "FIZZ BUZZ".
If n < 2, Fib() returns the the vaue of n.
If n > 2, Fib() creates an empty array of doubles and passes n and the array to the method calcFib().
If n < 2, calcFib() returns the the vaue of n.
If the desired value exists in the array already, calcFib returns the value.
If the value needs to be calculated calcFib() performs a recursive calculation such as calcFib(3) = calcFib(2) + calcFib(1).
It also saves the calculated value in the array so it can be looked up later, if needed.
For the 1st cycle, the value "4" and the array "4, 2, 3, 1" is passed in.
The for-loop executes 4 times.
The first and second elements of the array are compared, "4, 2, 3, 1" and if the number on the left is larger the elements are swapped.
In this case it is true so the array becomes, "2, 4, 3, 1"
This effectively moves the largest number in the array from the left to the right resulting in the array, "2, 3, 1, 4"
When the 2nd cycle of "sort2" runs the the value "3" and the array "2, 3, 1, 4" is passed in.
After this for-loop the array becomes "2, 1, 3, 4", essentially moving the second largest number in the array to the right.
The process is continued until the array becomes, "1, 2, 3, 4".
This static method takes in an array but doesn't return a value.
It just prints the array to the console.
I created it because the code was repeating.
C# delegates are similar to pointers to functions, in C or C++.
A delegate is a reference type variable that holds the reference to a method.
The reference can be changed at runtime.
Delegates are especially used for implementing events and the call-back methods.
All delegates are implicitly derived from the System.