I know that I can create new constant strings by concatenating other constant strings:
const string a = "A";
const string ab = a + "B";
Is it somehow possible to create a constant string based on a constant int? For example, the following won't compile:
const int Dpi = 300;
const string DeviceInfo = "<DeviceInfo><Dpi>" + Dpi + "</Dpi></DeviceInfo>";
The expression assigned to MyClass.DeviceInfo must be constant.
I know that I could work around this by
- making
Dpia string instead of an int (andint.Parseing it when I need the int value), - adding a second string constant
DpiString(and, thus, violating DRY), or - making
DeviceInfoastatic readonlyfield instead of aconstfield.
I'm going to go with option 3, but, out of curiosity, I was wondering if there is some other option that I missed...
string + objectuses a culture-sensitive conversion forobject? Good to know, the documentation is unfortunately not very clear on that.