try and catch Statements

try and catch Statements

You can handle errors by using a try...catch statement. You wrap the code that you suspect to trigger an error inside a try block. The catch block contains the codes to be executed when an error…
Unhandled Exceptions

Unhandled Exceptions

Unhandled exceptions are exceptions that were not properly handled by the program causing the program to terminate. We will demonstrate here what will happen if a program detects an exception during…
Exception Handling and Debugging

Exception Handling and Debugging

No matter how good a programmer is, he will always encounter errors or bugs. Testing for errors eats up a large percentage of program development. It would be better if…
String Interpolation

String Interpolation

String interpolation or interpolated strings allows you to specify expressions right within a string literal for better readability. The string literal will serve as a template containing interpolation expressions that…
Indexers

Indexers

Indexers allow you to access an element of a private array or collection field. When you indicate an index for an instance of a class, indexers will get the right data…
Arrays for Classes

Arrays for Classes

You can use arrays of objects. Creating arrays of objects is pretty much the same as when creating arrays for primitive data types such as int. For example, we can create…
Overloading Conversion Operators

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

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

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

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 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

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# 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

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

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.…