简体   繁体   中英

Why doesn't C# VS2017 intellisense work with var and local functions?

Why doesn't Intellisense work if I do something like this.

在此处输入图片说明

It does work though if I explicitly declare Foo

在此处输入图片说明

The problem reproes. It is a problem with parsing incomplete code.

The line that you started ( foo. ) gets parsed together with the local function on the line below. This causes the local function not to be parsed correctly, so VS doesn't know that GetFoo is a local function any more or that it returns a Foo .

This is likely a bug in visual studio. As a work around, you can get the intellisense to play nice in this situation by declaring GetFoo at the top of your function's scope.

void Test()
{
    Foo GetFoo() => new Foo();

    var foo = GetFoo();
    foo.DoThing();

}

智能感知工作

I observe the same behavior you have when placing the GetFoo declaration below the point in which I'm trying to use it, so it would seem that order matters.

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