Posts

Overloading In C#

Overloading - When the derived class methods uses the same name, arguments and return type as a method in base class. Function must be differ by the arity (Different number of argument) and datatype. public class Class : Class1     {         public void Method1( int num1)         {         }     }     public class Class1     {         public void Method1()         {         }     } x

Types of Constructor in C#

Constructor - Constructor is special kind of methods used for initialization of a class. Types of Constructors                 Default – Without having any parameter                 publicstring fName; public clsConnect()         {             fName = "First Name" ;         }                 Parameterized – Constructor at least one parameter                 publicstring fName; public clsConnect( string sFName)         {             fName = sFName...

Sealed Keyword in C#

Image
Sealed Class – if this keyword is used on a class then it will not allow to inheritance that class and if it is used on method then it will restrict the override of that method. Sealed Method - This keyword is basically used to restrict a class for inheritance and  preventing the inheritance  Cannot be inherited

Delegates in C#

Delegates – it’s a type that holds the reference of method in an object. It’s also called type safe (It ensure that operation is working on right kind of data) function pointer. Adv –    Encapsulating the method call from caller                 Effective use of delegate improve the performance                 Use to call method asynchronously.                 Declare Delegate ->Public Delegate int delegate_name(Param optional)                 Multicast Delegate – holds the reference of more than one method. Must contain the methods return void. How to use                 Single Delegate ...

OOPS (Object Oriented Programming) Properties

OOPS (Object Oriented Programming) properties Encapsulation – The programmer can hind the data and function in class from other classes. It is accomplished through assess modifier. Abstraction – Allow us to define a common definition of a base class that multiple derived classes can share. Abstract class is the example of this property Polymorphisms – One interface with many different forms. There are 2 types of polymorphisms. ·          Compile Time – Function and operator overloading ·          Run Time – Inheritance & virtual function Inheritance – Class includes the properties of another class.  It represents the relationship between two classes where one type drives the functionality of second type. Classes – Primary building blocks of OOPs. It also serves as a templet that describe property, methods etc. Object – Object is an instance of a class in OOP. It can be a ...

UML(Unified Modeling Language)

UML (Unified Modeling Language) – Consist of boxes representing classes. Each box has 3 parts (Top, Middle and Bottom).                 Top Part – Class/Package name Middle Part – Class variables (+ Sign ->Public, - Sign ->Private, # Sign -> Protected) Bottom Part – List of Methods UML Relationships Association – Is a structural relationship between two modal elements that shows that objects of one classifier connect and can navigate to objects of other classifier. Let’s take an example of doctor and patient relationship. A doctor can associated with multiple patients and same time a patient can visit multiple doctors. Each of these objects has their own life cycle and there is no owner. Aggregation – It’s an association between the objects in which the objects has their own life cycle but there exists an ownership as well. As an example an employee may belongs to multiple department ...

Extension Methods in C#

Image
Extension Method          These are the special kind of methods those allows us to add methods to existing types without modifying the original types How we can write the Extension Methods           Few things we have to remember before we write a extension method 1. The wrapper class under which we declare the extension methods should be static class 2. Method should be static method Lets get started In this post I am going to add an extension method under string type. Step 1 Write extension class     public static class ExtensionStringMethods     {         public static string GetAllUpperCase(this string obj)         {             return (obj.ToString().ToUpper());         }     } Step 2 Call extension methods         private void GetUpper(string strInput)     ...