I have a class that contains two methods like these:
public String getFoo(Int32 a)
{
return getBar(a, "b", null);
}
public String getBar(Int32 a, String b, Int32 c)
{
//do something
return "";
}
However when I compile my class I get two errors:
- The best overloaded method match for getBar(int,string,int) has some invalid arguments
- Argument '3': cannot convert from '
<null>
' to 'int'
I think I understand why I'm getting this error: the compiler doesn't know at the time of compilation what the real type of the object is. Can someone confirm if I'm correct about the cause of the error or point out the real reason?
More importantly, can I design my code this way? If so, what do I need to do to fix the errors? My reason for designing my class this way is because I don't want to duplicate the code in getBar, in getFoo. The two methods do essentially the same thing except one takes a third parameter.
Thanks.