I'm trying to use an optional array in a Sub but am having troublefiguring out how to assign the default value.For instance:Sub MySub(Optional MyString as String() = ... )I want to put an empty array in there but can't quite figure out howthat should work.Can someone point me in the right direction?
Optional arguments are probably the wrong way and not CLS compliant.Overloading is better.
Sub MySub( )Dim strParm() As String = {"up", "down", "left", "right"}Call MySub(strParm())End SubSub MySub(MyString as String() ).....End Sub
Are there any performance hits to using optional params? What do you meanby CLS compliant? I always kind of thought it all compiled down to the samecode when it was all said and done.
Basically there are some things you can do in C# and VB.net that meansother languages may not be able to inherit the code and/or consume it properly.For example C# supports unsigned INTs which are not a type that all .netlanguages are guaranteed to support. If one used them as parameters to afunction a language like VB.net or Perl.net could not call that function.If the unsigned INT happened inside the function any language could callthat function but if it appeared as parameter/signature a language thatcould not construct an unsigned INT would have trouble calling it.Same thing with Case Sensitive methods in C#C# could call a DoTask() or doTask() method and would be calling 2 distinctmethods because their are 2 separate mothods case-sensitivity is what makesthem different.If VB.net called the function Dotask or any of the capitalization variantsit would be ambigous which to call so we would call the C# class with casesensitive methods "NOT CLS compliant".C# and VB.net compilers have switches to check for CLS compliant and warnif violated.There are other good practices besides CLS compliance that FXCOP can catch.....http://www.gotdotnet.com/team/libraries/Just because code works and is fast enough does not ensure it iswritten the best way.