Why does the compiler say ‘a constant value is required’ for the first case…the second case works fine…
switch (definingGroup) { case Properties.Settings.Default.OU_HomeOffice: //do something break; case 'OU=Home Office': //do something break; default: break; }
also tried…
switch (definingGroup) { case Properties.Settings.Default.OU_HomeOffice.ToString(): //do something break; case 'OU=Home Office': //do something break; default: break; }
…same error
Here’s the Properties.Setting code
[global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute('OU=Home Office')] public string OU_HomeOffice { get { return ((string)(this['OU_HomeOffice'])); } }
Properties.Settings.Default.OU_HomeOfficeisn’t a constant string – something known at compile time. The C# switch statement requires that every case is a compile-time constant.(Apart from anything else, that’s the only way it can know that there won’t be any duplicates.)
See section 8.7.2 of the C# 3.0 spec for more details.