Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Constructor

Constructor

Scheduled Pinned Locked Moved C#
tutorialhelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imran_Shaikh
    wrote on last edited by
    #1

    :rose:What is constructor and how to use it pls help me about constructor with simple Example Thanks,

    C T 2 Replies Last reply
    0
    • I imran_Shaikh

      :rose:What is constructor and how to use it pls help me about constructor with simple Example Thanks,

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      imran_Shaikh wrote:

      What is constructor

      A constructor initialises a new instance of an object.

      imran_Shaikh wrote:

      how to use it

      public class MyCoolClass
      {
      public MyCoolClass()
      {
      // This is a constructor. It is just a special type of method.
      // Initialise the new instance of the class here
      }
      }

      class Program
      {
      static void Main()
      {
      MyCoolClass aCoolObject = new MyCoolClass();
      }
      }


      Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

      1 Reply Last reply
      0
      • I imran_Shaikh

        :rose:What is constructor and how to use it pls help me about constructor with simple Example Thanks,

        T Offline
        T Offline
        turbochimp
        wrote on last edited by
        #3

        Basically, constructors are special methods that are called when an instance of a class is created. Unless the class is marked 'static', a public default (parameterless) constructor is created for it by the compiler. Here is an article that has examples.

        The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups