Constructor in C#

Constructor is like a method.

1. Constructor has the same name as a class name.

2. Constructor doesn’t have any return type.

3. Constructor didn’t call by programmer it is called automatic whenever class object is created.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace ConsoleApplication4

{

    class Program

    {

        public static void Main(string[] args)

        {

            ABC OBJ = new ABC();

 

        }

    }

 

    class ABC

    {

        public ABC()

        {

            Console.WriteLine("Constructor Called");

        }

    }

}

 

  Modified On Nov-29-2017 01:26:14 PM

Leave Comment