1

Suppose I have this code (all in the same class):

#if CONDITION
    private static readonly string firstName = "First Name";
#endif

    string GetName(){
#if CONDITION
        return firstName;
#endif
        return "Second Name";
    }

It is giving me the error The name 'firstName' does not exist in the current context in the function GetName().

How can I fix this error?

Daniel
  • 7,357
  • 7
  • 32
  • 84
  • 2
    Can't reproduce? https://dotnetfiddle.net/j3D6rw - can you provide a fiddle that does, e.g. https://dotnetfiddle.net/d4E1Fh (but not that form, for obvious reasons) – Caius Jard Jan 04 '22 at 06:48
  • Is the first If Condition always true? If not i guess the firstName is never declared. – stersym Jan 04 '22 at 07:26

0 Answers0