The method DoSomething()
does Create an Instance of MyClass
but not everyone wants to know the MyClass-Object
sometimes it also fits if you simply know if the action was successful.
public bool DoSomething(out Myclass myclass = null)
{
// Do something
}
A ref or out parameter cannot have a default value
Sure I could simply remove the out-Keyword
but then I needed to assign any variable first, which is not my intention.
public Myclass DoSomething() //returns null if not successful
{
// Do something
}
Does anyone know a nice Workaround for that?
Just by overloading:
public bool DoSomething()
{
myClass i;
return DoSomething(out i);
}
public bool DoSomething(out myClass myclass)
{
myclass = whatever;
return true;
}
And then call DoSomething()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With