How many constructor a class have in C# ?

Is it known as constructor overloading ?

//we can also print it from constructor
using System;


namespace ConstructorOverloading
{
    class GameScore
    {
         string user;
         int age;
         int salary;

        public GameScore() //it is default constructor
        {
            user = "Steven";
            age = 28;
            Console.WriteLine("Previous user: "+user+" and he was "+age+" year old");
        }

        public GameScore(string name,int age)
        {
            user = name;
            this.age = age;
            Console.WriteLine("Current user {0} and he is {1} years old",user,this.age);
        }

        public GameScore(int age, int salary)
        {
            this.age = age;
            this.salary = salary;
            Console.WriteLine("From the third constructor Age="+age+" Salary:"+salary);
        }

        public void Display(int no)
        {
            Console.WriteLine("Output from "+no+" no. Constructor");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            GameScore g1=new GameScore();
            GameScore g2=new GameScore("Zaki",25);
            GameScore g3=new GameScore(90,99);
            g3.Display(3);
            Console.ReadKey();
        }
    }
}

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

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