.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles


Posted By:Shashi Ray       Posted Date: February 22, 2009    Points: 10    Category: C#    URL: http://www.dotnetspark.com  



All classes have specific constructors that are called when you create an instance of a class. These constructors always have the same name as the class. This applies to form classes as well as non- visual classes. Here is the constructor the system generates for our simple hello window in the class Form1:


public class Form1 {

public Form1(){ //constructor




When you create your own classes, you must create constructor methods to initialize them, and can pass arguments into the class to initialize class parameters to specific values. If you do not specifically include a constructor in any class you write, a constructor having no arguments is

generated for you under the covers.


The InitializeComponent method is generated by the IDE as well, and contains code that creates and positions all the visual controls in that window. If we need to set up additional code as part of the initialization of a Form class, we will always write a private init method that we call after

the InitializeComponent method call.


public Form1(){




private void init() {

x = 12.5f; //set initial value of x




Shashi Ray

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend