With this code:
public partial class Form1 : Form
{
private static readonly int TABCONTROL_BASICINFO = 0;
private static readonly int TABCONTROL_CONFIDENTIALINFO = 1;
private static readonly int TABCONTROL_ROLESANDSECURITY = 2;
private static readonly int TABCONTROL_INACTIVEINFO = 3;
. . .
int ActiveTabPage = tabControlWorker.SelectedIndex;
switch (ActiveTabPage) {
case TABCONTROL_BASICINFO:
if (currentNode == "NodeBuckingham") {
} else if (currentNode == "NodeNamath") {
} else if (currentNode == "NodeParsons") {
} else {
}
break;
…I have to replace “TABCONTROL_BASICINFO” with “0”, or I get, “A constant value is
expected”
Heavens to Murgatroyd! Can’t it look up and see that TABCONTROL_BASICINFO is 0?
If you want to make it a constant expression as far as the compiler is concerned, declare it as a
const:Or follow .NET naming conventions…
Or use an enum, given that you’ve basically got a fixed set of values:
By the way, you can also switch on strings in C#, so this:
Can become: