oscilatingcretin
oscilatingcretin

Reputation: 10919

VB.NET vs C#: Anonymous types and intellisense

How come when do this in C#...

var x = new { Name = "aaa" };

...I can get intellisense on .Name, but when I do this in VB.NET...

Dim x = New With {.Name = "aaa"}

...I get no intellisene on .Name?

Upvotes: 5

Views: 669

Answers (2)

Soner Gönül
Soner Gönül

Reputation: 98750

This sounds a momentary situation to me. Because when I try,

Dim x = New With {.Name = "aaa"}

It shows

enter image description here

Consider also Option Infer Statement

Enables the use of local type inference in declaring variables.

Upvotes: 6

oscilatingcretin
oscilatingcretin

Reputation: 10919

Answering my own question here. In VB.NET, you have to use the module level option infer on.

I was going to just delete this question after I figured out the problem, but 1) I can't because this question already has an answer and 2) I am sure this will be helpful to others anyway.

Happy inferring.

Upvotes: 2

Related Questions