Absolutely. VB.NET and C# provide methods called constructors that allow you to specify how an object can be instantiated. This method is called new in VB.NET. In C#, it's simply the name of the class. For example: 'VB.NET Class MyObject Public overloads Sub New() 'do something End Sub Public overloads Sub New(strString as string) 'do something ... end sub End Class //C# class MyObject { public MyObject() { 'do something } public MyObject(string strString) { //do something ... } } This class has two constructors a default one that doesn't take any parameters, and one that takes a single string parameter. Inside the second constructor, you can perform any operation you want that uses that string. You could use the following line from an ASP.NET page: dim objMyObject as new MyObject("hello!") There are just a few things you need to know. Also be aware that you can only instantiate objects with the constructors you build. If you don't provide a constructor that doesn't take any parameters, you cannot do the following: dim objMyObject as new MyObject If you don't provide any constructors at all, VB.NET and C# automatically create one for you that doesn't take any parameters. Also, if you provide multiple constructors, be sure to use the overloads keyword in VB.NET to avoid errors that arise from having two methods with the same name. For more information, see the VB.NET and C# documentation included with the .NET Framework SDK. |