calling constructor from another constructor

In this example, we are calling no argument constructor from a two argument constructor and a two argument constructor from a one argument constructor

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;


namespace ConsoleApplication6
{   
    class Program
    {
        public Program()
        {
            
            Console.WriteLine("this is no argument");
        }

        public Program(int feet) : this(feet,40)
        {
            Console.WriteLine("this is one argument constructor");

        }
        public Program(int feet, int inches) : this()
        {
            Console.WriteLine("this is two argument constructor");
        }       
         
        static void Main(string[] args)
        {
          //  Program p = new Program();
          //  Program p1 = new Program(10);
            Program p2 = new Program(20, 30);
         }        
        
    }
}

 

Add a Comment

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