Compiler says variables declared within compiler directive doesnt exist

54 views Asked by At

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?

0

There are 0 answers