C#-1 Flashcards
Classes and Interfaces
In a traditional object-oriented paradigm, the only kind of type is a class. In C#, there are several other kinds of types, one of which is an interface. An interface is like a class, except that it only describes members. The implementation for those members comes from types that implement the interface. Interfaces are particularly useful in scenarios where multiple inheritance is required (unlike languages such as C++ and Eiffel, C# does not support multiple inheritance of classes.)
C# overview
C# is a general-purpose, type-safe, object-oriented programming language. The goal of the language is programmer productivity. To this end, the language balances simplicity, expressiveness, and performance. The chief architect of the language since its first version is Anders Hejlsberg (creator of Turbo Pascal and architect of Delphi). The C# language is platform-neutral, but it was written to work well with the Microsoft .NET
Inheritance
An example is a base class called Asset and subclasses called house and stock, using this syntax asset : house
Polymorphism
References are polymorphic. This means a variable of type x can refer to an object that subclasses x. For instance, consider the following method:
public static void Display (Asset asset)
{ System.Console.WriteLine (asset.Name); }
This method can display both a Stock and a House, since they are both Assets: Stock msft = new Stock ... ; House mansion = new House ... ; Display (msft); Display (mansion);
Polymorphism works on the basis that subclasses (Stock and House) have all the features of their base class (Asset). The converse, however, is not true. If Display was modified to accept a House, you could not pass in an Asset:
static void Main() { Display (new Asset()); } // Compile-time error public static void Display (House house) // Will not accept Asset { System.Console.WriteLine (house.Mortgage); }
Events
Events are function members that simplify acting on object state
Type
Unified type system The fundamental building block in C# is an encapsulated unit of data and functions called a type. C# has a unified type system, where all types ultimately share a common base type. This means that all types, whether they represent business objects or are primitive types such as numbers, share the same basic set of functionality. For example, an instance of any type can be converted to a string by calling its ToString
Abstract
An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.
Catch
test
Checked
test
Delegate (simple)
Delegates A delegate is an object that knows how to call a method
Explicit
test
Extern
test
Finally
test
Fixed
test
Implicit
test
Internal
test
Lock
test
Namespace
test
New
test
Object
test