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?

2
  • 2
    Can't reproduce? dotnetfiddle.net/j3D6rw - can you provide a fiddle that does, e.g. dotnetfiddle.net/d4E1Fh (but not that form, for obvious reasons) Commented Jan 4, 2022 at 6:48
  • Is the first If Condition always true? If not i guess the firstName is never declared. Commented Jan 4, 2022 at 7:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.