Archives for C# - Page 5
Overloading Conversion Operators
You can overload the conversion behaviors in C#. For example, what if you want to convert one class into an unrelated class. We can overload the effect of casting or…
as Operator
You can use the as operator in C# to convert a class into another class within the same inheritance hierarchy. The as operator is equivalent to using casting with some minor differences as will…
Polymorphism
Polymorphism allows classes to transform into a different class within its inheritance hierarchy. It allows a programmer to use objects of different types but treat them in their “general” form while…
Partial Classes
Partial classes allows you to define a class in multiple seperate files. For example, you can place all the fields, properties, and constructors inside a file, and place all the methods…
Sealed Classes
Sealed class are classes that cannot be inherited by other class. Since sealed-classes cannot be inherited, they cannot be abstract. The following program shows an example of a sealed-class. namespace SealedClassesDemo…
Abstract Classes
Abstract classes are classes that always serves as base class for other classes. Abstract classes are slightly similar to interfaces but abstract classes can also have methods and properties that already…
C# Interface
C# Interfaces are similar to classes, but it only contains declarations for methods and properties. Interfaces can be considered as plugins to classes. The class that implements a particular interface is…
is Operator
The is operator in C# allows you to test if an object can be converted into another object mainly by using casting. The is operator requires two operands, the one that will be tested,…
Operator Overloading
Operator overloading allows you to customize the behaviors of C# operators depending on the type of its operands. Operator overloading allows a C# operator to interpret objects in a different way.…
Containment
Containment or composition is the process of adding another class as a member of a class. For example, a Person class can have a field of type Name. The program below shows an example…