News, code, articles, rants; a daily dose of programming rigmarole.

Thursday, February 22, 2007

Answer to What's Wrong With This Code

I can't believe it's Thursday already!! Yes, I forgot to post the answer to the previous problem yesterday, so here it is:

Looks like 3_4 on 7 got it right:

3_4 on 7 said...

I don't believe this would compile. I'm not sure what the output would be but, since C# does not support optional parameters, I believe you're required to supply a value for all of the parameters, including the optional parameters.

However, the VB developer in this instance should make sure that their code is never going to be in a library that is being used by another language as including a universally unsupported concept like optional parameters would be poor development practice.

C# does NOT (to my dismay and probably the dismay of many other developers) support optional parameters, therefore when referencing the code in C#, it would display the parameter list as having required parameters. See you next time!!

3 comments:

Anonymous said...

Properly written, it supports optional parameters... It's called constructor overloading :) Toss in a little bit of constructor chaining and you save yourself from code duplication.

C# rules!

Anonymous said...

Actually, in this instance, you weren't constructing the object...Just building a function/method so let's just say that method overloading is what we desire here...

Principle of chaining still applies. :)

And C# still rules.

Anonymous said...

Mr Muteness,
It seems you know a lot about computers. I am an old person from Stuart, Florida and I was wondering if you could answer a question for me.

If I get Microsoft put on my computer, will I internet?