In this (hopefully) multi-part series, I will be presenting challenging (maybe to over-glorified web developers or egocentric re-implementers like previous developers I've worked with, you know who you are! =^) programming problems that readers can solve via comments, and I will respond either with the winning comment or just the answer because nobody responded, in which case I will cry.
What's Wrong With This Code?
Say you have the following VB code:
Public Class Adder
Public Shared Function Add( ByVal a As Integer, ByVal b As Integer, Optional ByVal c As Integer = 0) As Integer
Return a + b + c
End Function
End Class
Then you have the following C# code referencing the previous VB code:
public class AdderClient{
public static void CallAdder(){
Console.WriteLine(Adder.Add( 1, 2 ));
}
}
Will this compile? Why/why not? What would the output be?
The answer will come Wednesday!
News, code, articles, rants; a daily dose of programming rigmarole.
Monday, February 19, 2007
Subscribe to:
Post Comments (Atom)

6 comments:
There are two problems with this code:
1) It was written by a moron
2) It is in VB
I'm not really interested in syntax trivia.
What I'd really like to see is a blog about custom attributes that, when implemented properly, can completely alleviate the need for unit testing.
Could you please provide some source code on that?
Can you show us how to use parameterized polymorphism to promote loose coupling besides using generic collections?
Forget the code...Whats worng with this picture!
http://www.flickr.com/photos/carlosmuentes/133207629/
Looks like you are not the only one who loves your wife.
As a computer tech I don't know much about coding, but judging from this blog you don't either.
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.
Post a Comment