Another object similar to enumerated types?

S

SamIAm

Hi There

I need to record various error codes in my application. These error codes
are from a 3rd party product that I get return codes from when I call their
methods. They are stored as string values i.e. "EQ832" =
"InvalidCodeEntered".

I need to take action based on the return codes like:
string returnCode = SomeFunction(value1, value2);
switch (returnCode){
case "EQ832":
// Take Action
break;
case "EQ833":
// Take Action
break;
}

I would like to have a way of giving the error codes a more meaningfull name
to use in my application. So I can do something like:
string returnCode = SomeFunction(value1, value2);
switch (returnCode){
case ReturnCodes.InvalidCodeEntered:
// Take Action
break;
case ReturnCodes.InvalidMerchantNumber:
// Take Action
break;
}

I cannot use enumerated types as they can only represent integer values. So
I created a class similar to:
public sealed class ReturnCodes
{
private ReturnCodes()
{}

public static string InvalidCodeEntered = "QE832";
public static string InvalidMerchantNumber= "QE833";

}

I can then access the class in my application by using:
ReturnCodes.InvalidCodeEntered

Is there a better way of doing this?

Thanks,

S
 
J

Jeff Louie

You can return user defined structures and you can convert error strings
to a numeric (int) hashcode using "some string".GetHashCode().

Regards,
Jeff
I cannot use enumerated types as they can only represent integer
values.<
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top