Hi All,
I'm new to C#, but I'm pretty sure I've seen this done in Java so I'm sure it can be done here. What I would like to do is dyanmically generate the name of the constant I would like to read. Here is an example of what I want to do.
In a separate file for constants (ConstantsFile.cs):
public static String CODE_A = "1;
public static String CODE_B = "2;
In another file, in some method, refer to these constants "dynamically" (I don't know what to call it):
String sCodeValue="A"; // This value would be unknown
// but is given here to clarify
String sConstantValue=ConstantsFile.CODE_(+sCodeValue)
// I want to pull the value of ConstantsFile.CODE_A,
// so in this case, sConstantValue would be set to "1"
So, it's the last line that I really don't know how to write. I would like the constant name to be appended with the code value which has come in. If that can't be done in that way, it's also fine for me to do something like:
String sCodeValue="A";
sCodeValue="CODE_"+sCodeValue;
String sConstantValue=ConstantFile.(sCodeValue)
I just can't figure out how to do it. This can be done, right? Am I seeking something that has a much more complex solution?
Thanks in advance,
Liz
I'm new to C#, but I'm pretty sure I've seen this done in Java so I'm sure it can be done here. What I would like to do is dyanmically generate the name of the constant I would like to read. Here is an example of what I want to do.
In a separate file for constants (ConstantsFile.cs):
public static String CODE_A = "1;
public static String CODE_B = "2;
In another file, in some method, refer to these constants "dynamically" (I don't know what to call it):
String sCodeValue="A"; // This value would be unknown
// but is given here to clarify
String sConstantValue=ConstantsFile.CODE_(+sCodeValue)
// I want to pull the value of ConstantsFile.CODE_A,
// so in this case, sConstantValue would be set to "1"
So, it's the last line that I really don't know how to write. I would like the constant name to be appended with the code value which has come in. If that can't be done in that way, it's also fine for me to do something like:
String sCodeValue="A";
sCodeValue="CODE_"+sCodeValue;
String sConstantValue=ConstantFile.(sCodeValue)
I just can't figure out how to do it. This can be done, right? Am I seeking something that has a much more complex solution?
Thanks in advance,
Liz