C Sharp Aggregation

C# Aggregation (HAS-A Relationship) The process of defining a class as an entity reference by another class is called aggregation in C#. Thus it can be used to reuse a class. It represents a HAS-A relationship as a form of association. Example: using System; public class Details { public int age; public string city; public … Read more

Categories C#

C Sharp Inheritance

C# Inheritance An object acquires all the properties and behaviors of its parent object automatically by using the process of inheritance in C#. It is useful when required to reuse, extend or modify the attributes and behaviors defined in a different class. The derived class in C# is the class that inherits the members of … Read more

Categories C#

C Sharp Properties

C# Properties Without any storage location, the C# Properties are accessed like fields and are an extension of fields. It can be read-only or write-only. To set, get or compute the values of the properties, they have accessors and while setting the values, the users can have logic. The fields can’t be accessed from outside … Read more

Categories C#

C Sharp Enum

C# Enum Also known as enumeration, enum in C# is used to store a set of named constants (also known as enumerators). Constant can be anything like seasons, days, months, size, etc. Declared within or outside class and structs, enumerators have default values starting from 0 and are incremented one by one. The default value … Read more

Categories C#

C Sharp Structs

C# Structs To create an instance of a class in C#, classes and structs are used. Classes and structs are blueprints. Classes in C# are a reference type. The structs are however value type. Also for lightweight objects like Color, Rectangle, Point, etc., the structs are used. In case the data is not intended to … Read more

Categories C#

C Sharp static constructor

C# static constructor To initialize the static fields and to perform an action to be performed only once, the C# static constructor is used. Before the first instance is created or any static members are referenced, the static constructor is invoked implicitly and automatically. It can’t have any modifier or parameter and can’t be called … Read more

Categories C#

C Sharp static class

C# static class Similar to the normal class is the C# static class. However, it can’t be instantiated. Having only static members, it also provides the guarantee that instance of the static class can’t be created. It is sealed and can’t contain instance constructors. Example: using System; public sttic class Example { public static float … Read more

Categories C#

C Sharp static keyword

C# static Instead of the instance, the static keyword or modifier in C# belongs to the type. Thus the static members do not need an instance for its access. The static in C# can be field, method, constructor, class, properties, operator or event, but the indexers and destructors cannot be static. Advantages: The C# static … Read more

Categories C#

C Sharp this keyword

C# this To refer to the current instance of the class, “this” keyword is used in C#. Uses of this keyword in C#: To refer to the current class instance variable to easily distinguish the instance variables or the field names and names of the parameters in case they are the same. To pass the … Read more

Categories C#

C Sharp Destructor

C# Destructor Just opposite to a C# constructor, a destructor in C# destructs the objects of classes. It is invoked automatically and is defined only once in a class. A destructor in C# can’t be public, can’t apply modifiers and can’t have parameters. Example: using System; public class Cities { public Cities() { Console.WriteLine("Constructed"); } … Read more

Categories C#