by Miha Markič
15. November 2007 12:11
In previous post I was asking whether a method returning an unassigned variable will compile and the answer is no, it won't. So this brings an interesting question, how do you initialize default values?
Are you doing something like this (1) - assigning default value right at the start:
bool Tubo(string text)
{
bool value = false;
if (text == "Tubo")
value = true;
return value;
}
or this (2):
bool Tubo(string text)
{
bool value;
if (text == "Tubo")
value = true;
else
value = false;
return value;
}
or this one (3) (valid only for bool results):
bool Tubo(string text)
{
bool value = text == "Tubo";
return value;
}
Personally I would go with the last one if I am dealing with bool values. If not, I prefer the first one.
aa97fce0-9244-4adb-a709-6d421a5b89cb|0|.0
Tags:
.net