I have a method that will get string, but before I can work with it, I need to convert it to int. Sometimes it can be null, and I need to change its value to "0". Today I have:
public void doSomeWork(string value)
{
int SomeValue = int.Parse(value ?? "0");
}
I did this, but my boss asked me to reorganize it:
public void doSomeWork(string value)
{
if(string.IsNullOrEmpty(value))
value = "0";
int SomeValue = int.Parse(value);
}
In your opinion, what is the best option?
source
share