Why is a local function not always hidden in C#7?

前端 未结 4 788
谎友^
谎友^ 2021-01-03 21:43

What I am showing below, is rather a theoretical question. But I am interested in how the new C#7 compiler works and resolves local functions.

In C#7

4条回答
  •  悲&欢浪女
    2021-01-03 22:36

    As c# is a statically compiled language, i'd think all the functions are compiled before their encompassing scope is executed and therefor the innermost Main cannot be declared because a Main already exists from its' closure point of view (one level up).

    Note that this is not based on factual evidence but just my initial thoughts on the matter.

    After some research... I was wrong, mostly. My gut feeling does seem to imply the same behaviour, But not for the reasons I initially thought.

    @PetSerAl already explained in comment form better than I could have copied it from manuals so I defer to that answer.

提交回复
热议问题