Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nullable enums don't trigger intellisense for list of valid enum values in C#

Type this code in C#:

ConsoleColor c;

c = 

As soon as you finish typing c =, intellisense presents a list of values from the ConsoleColor enum as expected. Now change it to a nullable:

ConsoleColor? c;

c = 

After you type the =, you'd expect intellisense to do the same as before, but it doesn't. I can't even get the enum list to invoke with CTRL+SPACE. In order to get it intellisense to invoke properly, I have to type c.Value =, but that just results in a build error because you can't assign a value to a read-only property. Oddly, it works as expected in VB.NET:

Dim c As ConsoleColor?

c = ConsoleColor.Black

Is this just a bug/quirk?

like image 418
oscilatingcretin Avatar asked Oct 21 '22 09:10

oscilatingcretin


1 Answers

EDIT you can probably disregard my answer, since I'm using ReSharper. I forget that sometimes.

Here's a weird thing: In VS2012, if I type this:

ConsoleColor? c;
c= 

I get no IntelliSense. If I type this:

ConsoleColor? c;
c = 

I do get IntelliSense. For those who have trouble spotting the difference, it's the space between c and =. I also need to type another space after the = before IntelliSense pops up with suggestions.

like image 186
Rik Avatar answered Oct 23 '22 11:10

Rik