roslyn: "When variable type is apparent" doesn't apply to array initialization

This the same bug I filed https://github.com/dotnet/roslyn/issues/23907, but it stated that it was fixed.

Version Used: Version 15.8.0 Preview 1.0 [27628.0.d15.8]

Steps to Reproduce:

image


public class Foo
{
    public void Method()
    {
        var files = new string[0];
    }

}

Expected Behavior:

No message

Actual Behavior:

Message IDE0008 Use explicit type instead of ‘var’ ConsoleApp300 C:\Users\davkean\Source\Repos\ConsoleApp300\ConsoleApp300\Program.cs 6 Active

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 18 (17 by maintainers)

Most upvoted comments

@Neme12 That makes sense, I was grouping the following together when I filed https://github.com/dotnet/roslyn/issues/23714, but I like your idea better.

var i = new int[];
var i = 0;

@sharwell

It covers things like this:

I don’t think so. I would expect 0 to be classified as “not apparent”. var would only be suggested if you type var i = new int()