Is there a significant mechanical difference between these faux simulations of default parameters?
Posted
by ccomet
on Stack Overflow
See other posts from Stack Overflow
or by ccomet
Published on 2010-05-28T17:20:54Z
Indexed on
2010/05/28
17:41 UTC
Read the original article
Hit count: 302
C#4.0 introduced a very fancy and useful thing by allowing default parameters in methods. But C#3.0 doesn't. So if I want to simulate "default parameters", I have to create two of that method, one with those arguments and one without those arguments. There are two ways I could do this.
Version A - Call the other method
public string CutBetween(string str, string left, string right, bool inclusive)
{
return str.CutAfter(left, inclusive).CutBefore(right, inclusive);
}
public string CutBetween(string str, string left, string right)
{
return CutBetween(str, left, right, false);
}
Version B - Copy the method body
public string CutBetween(string str, string left, string right, bool inclusive)
{
return str.CutAfter(left, inclusive).CutBefore(right, inclusive);
}
public string CutBetween(string str, string left, string right)
{
return str.CutAfter(left, false).CutBefore(right, false);
}
Is there any real difference between these? This isn't a question about optimization or resource usage or anything (though part of it is my general goal of remaining consistent), I don't even think there is any significant effect in picking one method or the other, but I find it wiser to ask about these things than perchance faultily assume.
© Stack Overflow or respective owner