Constructors overloading in c#

Constructors-Overloading
In this chapter you will learn:

  • What is constructor overloading?
  • How to use constructor overloading in C# program?

What is Constructor Overloading?

Constructor Overloading is a technique to create multiple constructors with different set of parameters and different number of parameters. It allows us to use a class in a different manner. A same class may behave different type based on constructors overloading. With one object initialization it may show simple string message whereas in the second initialization of object with different parameter it may done arithmetic calculation.

  • Programming Example of Constructors Overloading

    Output

    Previous User Steven and he was 28 year old
    Current User Clark and he is 35 year old
    __

    Explanation

    Constructor Creating
    In this example we have create two constructors. One is default constructor which modifies the variable string user, int age with their value. Very next we have created another constructor with different set of parameter which overloaded previous variable value with its own parameterized value.

    Summary

    In this chapter you have learned what the constructor overloading is and how to use in program. You have also seen the benefit of using constructor overloading in program. In the next chapter, we will see some more programming example of constructors and destructors which will enhance your understanding of object initialization with constructors.


    Leave a Reply

    Your email address will not be published. Required fields are marked *