Consider a scenario that you have the following enum declared, which is used to define SQL operations (keeping it very simple):
public enum Operands
{
Equals,
GreaterThan,
LessThan,
NotEquals
}
Now, if the user wants to convert the enums to values that SQL server can understand (=, <>, <, > etc.), the following needs to be done:
string _opValue = "";
Operands _op = Operands.LessThan;
switch (_op)
{
case Operands.Equals:
_opValue = "=";
break;
case Operands.GreaterThan:
_opValue = ">";
break;
case Operands.LessThan:
_opValue = "<";
break;
case Operands.NotEquals:
_opValue = "<>";
break;
}
Not very convenient. What if, you could say:
Operands _op = Operands.LessThan;
Console.Write(_op.ToStringValue());
|