简体   繁体   中英

When declaring my second method in c# i get the error “Static local functions is not available in c# 7.3”

when i declared my first method

static void Generation()
{
}

it works perfectly fine but when i try to declare my second method using the same code

static void Rendering()
{
}

it get the error "Static local functions is not available in c# 7.3". i read that i can be fixed by writing

<LangVersion>8.0</LangVersion>

but i want to know why it works the first time and not the second.

Check your syntax, expecially with the order of braces {} etc...

It seems the compiler believes the second function is somehow inside the first one.

Error (in C# < 7.3)

static void Generation()
{
static void Rendering()
{
}
}

Correct:

static void Generation()
{
}
static void Rendering()
{
}

Note that many syntax errors inside the body of the first function could confuse the compiler, and make it believe that the first function has not been ended before the second. For instance, I'd suggest to double-check all pairs of () or {} or [] , and terminating ; .

When using C# 8, (or 7.3) it's not an error anymore because you can actually define static functions inside others, but as far as I understand your question, that's not what you intended to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM