[Quickfix-developers] Non-const constants
Brought to you by:
orenmnero
From: Brian E. <azz...@ya...> - 2008-06-26 16:32:05
|
Is there are a reason that constant strings in the .Net library are not "const"? For instance, the MsgType class defines a whole series of static string "constants" for all the known FIX message types (beginning with ALLOCATION and ending with XML_MESSAGE). Unfortunately, they are defined as "public static string" rather than "public const string". This may seem like a trivial difference, but it means that these values can't be used as part of a switch() statement. switch (msgType.getValue()) { case MsgType.HEARTBEAT: // Doesn't work - not a constant value } So, I end up making parallel classes that simply redefine the values in a "const" manner. public class MsgTypeConstants { public const string HEARTBEAT = "0"; ... } switch (msgType.getValue()) { case MsgTypeConstants.HEARTBEAT: // This works } Is there a reason for "static" instead of "const"? - Brian Erst Thynk Software, Inc. |