I have a custom class “Error” and some pre-created errors (let’s call them A, B and C). Now I’d love to group these pre-created ones under one group (for example, “StockErrors”) and use them kind of like an enum:
private void SomeFunction(Error NewError)
{
if (NewError == StockErrors.A) DoSomething(); // this is what I need.
}
Any ideas how I could accomplish this? It’s probably something extremely simple…
Thanks in advance!
Make a
staticclass calledStockErrorswithpublic static readonlyfields of typeErrorthat are initialized to the appropriate values. (You can also use properties)Depending on your
Errorclass, you may also need to override==,!=,Equals, andGetHashCodeto use value semantics.