Category «C# Language Basics»

C# – Interfaces

An interface is defined as a syntactical contract that all the classes inheriting the interface should follow. The interface defines the ‘what’ part of the syntactical contract and the deriving classes define the ‘how’ part of the syntactical contract. Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only …

C# – Polymorphism

The word polymorphism means having many forms. In object-oriented programming paradigm, polymorphism is often expressed as ‘one interface, multiple functions’. Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time. Static Polymorphism The mechanism of linking a …

C# – Preprocessor Directives

The preprocessor directives give instruction to the compiler to preprocess the information before actual compilation starts. All preprocessor directives begin with #, and only white-space characters may appear before a preprocessor directive on a line. Preprocessor directives are not statements, so they do not end with a semicolon (;). C# compiler does not have a …

C# – Regular Expressions

A regular expression is a pattern that could be matched against an input text. The .Net framework provides a regular expression engine that allows such matching. A pattern consists of one or more character literals, operators, or constructs. Constructs for Defining Regular Expressions There are various categories of characters, operators, and constructs that lets you …

Enumerated Types in C#

An enumerated type, or enum as it’s called in C#, offers a convenient way to create a structured set of symbols to represent constant values. Syntax: [access modifiers]enum <identifier> [:enum-base]{enum body} Example: enum Fabric :short { Cotton = 1, Silk = 2, Wool = 4, Rayon = 8, Other = 128 } Note: If the …