-1
    Static hashTimeDifferrence As HashSet(Of String) = New HashSet(Of String)

works fine

    Static hashTimeDifferrence = New HashSet(Of String)

doesn't

    Dim hashTimeDifferrence2 = New HashSet(Of String)

works because option infer is on.

I think it should work for dim and static.

Is this a bug in vb.net?

jmoreno
  • 12,752
  • 4
  • 60
  • 91
user4951
  • 32,206
  • 53
  • 172
  • 282
  • Possible duplicate of [Implicit typing; why just local variables?](https://stackoverflow.com/questions/824739/implicit-typing-why-just-local-variables) – Craig Jan 16 '19 at 20:33
  • May be related but not duplicate. – user4951 Jan 16 '19 at 20:40
  • 3
    It's clearly not a bug: the VB documentation states, "The data types of Static local variables cannot be inferred." I would expect the reasoning to be identical to module-level items, since `Static` is functionally defining a module-level item but with only local scope. – Craig Jan 16 '19 at 20:59
  • Bro. VB documentation? Where? – user4951 Jan 17 '19 at 03:50
  • Try pressing F1 in a VB document with a VB keyword highlighted. I have the help docs installed locally, but it's also all available on the web. In my local help docs, there is a "Visual Basic" node at the top level (underneath "Help Viewer Home"). – Craig Jan 18 '19 at 15:10
  • Also, please tag us (using the '@" character and our user name) so that we are notified of replies, otherwise it's easy to forget to come back and look at the question and see that there's a follow-up comment. – Craig Jan 18 '19 at 15:13

1 Answers1

0

There is no fundamental reason why, it is actually just a missed edge case from when Infer was introduced. The former VB PM Anthony Green used it as a reference in how to make breaking changes: https://github.com/dotnet/vblang/issues/312

jmoreno
  • 12,752
  • 4
  • 60
  • 91