Dec 13, 2019

CONSTRUCTOR OVERLOADING IN C#


OVERLOADING
constructor overloading , constructor overloading  in c++, overloading a constructor, constructor overloading examples
constructor overloading in c#

       “The mechanism of creating more than one of a class member of same name in a class is called Overloading.”
 If we create more than one method or constructor in a Class with same name then the Class will have method and constructor Overloading.
            Overloading is found when same name for the class member by different rules which are,
            1.    Different number of parameter
            2.    Different type of parameter
            3.    Different sequence of parameter

CONSTRUCTOR OVERLOADING

            We already know the rules to declare constructor that the name of constructor should be equal and same to the class name, so when we declare more than one constructor in a class then the mechanism will called constructor overloading.
            Different situation of constructor overloading

         1.    CONSTRUCTOR OVERLOADING OF DIFFERENT  NUMBER OF PARAMETER

The overloading of constructor in a class due to creating more than one constructor by providing different number of parameters of same data type to the constructors.. 
For example suppose Class name is Evaluation,
Public class Evaluation
{
   Public void Evaluation (int a, int b)
      {
Do this;
      }
   Public void Evaluation (int a, int b, int c)
      {
Do this;
      }
   Public void Evaluation (int a, int b, in t c, int d)
     {
Do this;
      }
}

      2.    CONSTRUCTOR OVERLOADING OF DIFFERENT TYPE OF PARAMETER

 The overloading of constructor in a class due to creating more than one constructor by
providing different types of parameter to the constructors. 
For example suppose Class name is Evaluation,
Public class Evaluation
{
   Public void Evaluation (int a, double b)
      {
Do this;
      }
   Public void Evaluation(int a, double b, decimal c)
      {
Do this;
      }
   Public void Evaluation (int a, double b, decimal c, float d)
     {
Do this;
      }
}

           3.    CONSTRUCTOR OVERLOADING OF DIFFERENT SEQUENCE OF PARAMETER

The overloading of constructor in a class due to creating more than one constructor in a class by providing different sequence of parameters.
For example suppose method name is Evaluation,
Public class Evaluation
{
   Public void Evaluation (int a, decimal b, double c)
      {
Do this;
      }
   Public void Evaluation (double a, int b, decimal c)
      {
Do this;
      }
}


See example. GO

0 comments:

Post a Comment

Please do not enter any spam link in the comment box