You have to write ReturnCode.Success/Fail, no way around it.
Rather than define a ReturnCode enum and pollute all your code with
ReturnCode.Success/Fail, you should consider two options:
* Returning a bool value (true/false)
* Not returning anything (void) and throwing exceptions when something goes
wrong.
Usually, the best approach is a mixture of the two above: you return a bool
value when the caller can do something about the failure case, and you throw
an exception when the event is really abnormal and the caller won't be able
to do anything about it (but somewhere higher in the call chain -- usually
an event loop or event handler --, there is a method that will catch the
exception, report it to the user and let the application go on).
Bruno.
"C# beginner" <an*******@discussions.microsoft.com> a écrit dans le message
de news:2e****************************@phx.gbl...
namespace mynamespace
{
internal enum ReturnCode
{
Fail = -1,
Success = 0,
...
}
}
If I have to use the enumeration from a class that is in
the same namespace, do I still have to type,
ReturnCode.Fail, ReturnCode.Success ...etc. Is there
anyway I can avoid typing the name of the enumeration?
Any feedback is appreciated.