.NET Tip: Create a Class with Overloaded Constructors Atlanta GA

Overloading the constructor of a class, which is the method called when you instantiate an object, ensures that your object is populated with all the information it needs to operate properly.

Local Companies

Count5 Sales Force Alignment Solutions
404-961-7350
1800 Peachtree Street Suite 444
Atlanta, GA
A.D.A.M., Inc
404-6042-757
10 10th Street NE
Atlanta, GA
SecuredPay Solutions, Inc.
404-324-3449
640 MCGILL PL NE
Atlanta, GA
VIA Networks
(702)2738210
3565 Piedmont Rd Bldg 1 Ste 525
Atlanta, GA
Arke Systems
404-812-3123
3400 Peachtree Road
Atlanta, GA
Ingenium Software
770-394-7724
1851 Peeler Road
Atlanta, GA
Ingenium Software
770-394-7724
1851 Peeler Road
Atlanta, GA
Ingenium Software
770-394-7724
1851 Peeler Road
Atlanta, GA
Inside Corp
770-828-0100
4279 Roswell Rd
Atlanta, GA
Manhattan Associates
(770) 955-7070
2300 Windy Ridge Parkway
Matthews, NC

provided by: 
Originally published at Internet.com


When I create a class, I often define a constructor to ensure that the object is initially populated with all the information it needs to operate properly. As an example, one of my databound objects can take a database connection or both a database connection and an object representing the unique ID for the record. Each of these methods for instantiating the object is a separate constructor method. This tip teaches you how to overload the constructor of a class, which is the method called when you instantiate an object.

To see how this works, take a simple class (DataObject) that has three public variables on it: public class DataObject { public string Value1; public string Value2; public string Value3; public DataObject(string value1, string value2, string value3) { Value1 = value1; Value2 = value2; Value3 = value3; } public DataObject(DataRow inputRow) { Value1 = inputRow["value1"].ToString(); Value2 = inputRow["value2"].ToString(); Value3 = inputRow["value3"].ToString(); } }

One of the class's constructors will accept values for each of the three variables, and its other constructor will accept a DataRow that has values for each of the three variables. The code assumes that you have a database table somewhere that has fields named value1, value2, and value3, and that all three fields are strings.

To call this function, you can use one of the following methods, which will end up populating the DataObject class with the three values: DataObject obj1 = new DataObject("test1", "test2", "test3"); DataTable dt = DataObject obj2 = new DataObject(dt.Rows[0]);

You also can use this method to overload any method on your class. As long as the parameter list is different, you can add an additional overload. You can't, for instance, have two overloads that each has three string parameters. You can have one overload that accepts one string and another that accepts two strings.

About the Author

Eric Smith is the owner of Northstar Computer Systems, a Web-hosting company based in Indianapolis, Indiana. He is also a MCT and MCSD who has been developing with .NET since 2001. In addition, he has written or contributed to 12 books covering .NET, ASP, and Visual Basic.

Author: Eric Smith

Read article at Internet.com site

Featured Local Company

Count5 Sales Force Alignment Solutions

Count5 is a software company that improves a company's top line by driving accountability to the front line.

404-961-7350
1800 Peachtree Street Suite 444
Atlanta, GA
Sales Force Alignment

Count5 is a software company that improves a company's top line by driving accountability to the front line. Count5's sales force alignment solution - Q OnDemand - raises the success rate of sales strategies, CRM and service initiatives by improving alignment of the work force with change, and for the first time, by quantifying alignment so problems can be addressed by managers early before performance suffers. Q is a unique communications tool that automates ongoing reinforcement and coaching to frontline employees on a recurring schedule while tracking user participation and retention for managers. This patent-pending process rapidly improves alignment with new initiatives, strategy and messaging. Count5® was recently named by the Technology Association of Georgia (TAG) as one of Georgia's most innovative technology companies.

Available OnDemand, Q™ can be implemented to drive your next change initiative in less than 30 days.

For more information, call us at (404) 961-7350 or visit us online at www.count5.com.

Related Local Events
Astd Atlanta Technology Based Learning Sig Event 4Th Annual Elearning Excellence Awards
Dates: 12/10/2009 - 12/10/2009
Location: Knowledge Development Centers
Atlanta, GA
View Details

TAG CRM
Dates: 11/12/2009 - 11/12/2009
Location: Oracle - Building 500
Atlanta, GA
View Details

Southeast User Group Leader Summit
Dates: 10/24/2009 - 10/24/2009
Location: Microsoft Alpharetta
Alpharetta, GA
View Details

TAG Excalibur Awards 2009
Dates: 10/23/2009 - 10/23/2009
Location: Atlanta Buckhead Marriott
Atlanta, GA
View Details

Astd Atlanta Technology Based Learning Sig Event Scorm
Dates: 10/6/2009 - 10/6/2009
Location: Knowledge Development Centers
Atlanta, GA
View Details