As someone else already mentioned, you would not have repeated code if you
overload methods. The general rule is that the method with the most
parameters has all the logic, and all other overloaded methods call either
the main method, or another overloaded method. All your logic should be
contained in only one methd. For example (a simple example),
public int InitializeUSBDevice(int venderID, int productID, string command)
{
//Initialize USB device and send initialize command
return successCode
}
public int InitializeUSBDevice(int productID, string command)
{
return this.InitializeUSBDevice(this.defaultVendorID, productID, command);
}
public int InitializeUSBDevice(string command)
{
return this.InitializeUSBDevice(this.defaultProductID, command)
}
public int InitializeUSBDevice()
{
return this.InitializeUSBDevice(this.defaultCommand);
}
In addition, keep in mind that Optional parameters in VB.NET are not CLS
Compliant. If I have a VB.NET DLL with a method:
Public Function Add(ByVal param1 As Integer, ByVal Optional param2 As Integer)
'Do some work and return
Return result
End Function
The optional parameter "param2" would not be optional from a C# win app, or
a managed C++ win app ... or any .NET syntax (I hate using the word
"language"). In another other language other than VB, the second parameter
will always be required.
It's something to think about. Hope this helps.