5

When writing C# in Visual Studio (Community 2017), it's always really bugged me that when I have two similarly-named identifiers, one beginning with upper-case and one beginning with lower-case, that sometimes when I start typing in lower-case it'll autocomplete on the upper-case identifier instead.

This typically happens when I'm assigning from a lower-case parameter to an upper-case field/property, for example:

enter image description here

When I start typing my..., it matches the lower-case myValue until I type the v, at which point it starts to match the upper-case MyValue instead. Obviously I don't want this because then I'll end up with MyValue = MyValue! Is there any way that I can get it to resolve case ambiguities based on the case of the first letter only instead of whatever it's doing now? If I start typing in lower-case then I want it to continue matching the identifier beginning with lower-case as I type more characters.

Edit: Here's an example where it's matching a type instead of a variable. I've typed the parameter name in full, with proper case, and it's still matching a type rather than the variable:

enter image description here

Jeff
  • 7,504
  • 3
  • 25
  • 34
  • Fields should be named lowercase anyway, according to the C# coding standards. Then your code would become `this.myValue = myValue`. – adjan May 11 '17 at 17:59
  • 2
    Are you kidding? Two identifiers different only in case? Not really a smart choice. – Steve May 11 '17 at 17:59
  • Whether it's a field or property doesn't matter. It's just a toy example; the same behaviour happens if it were a property. – Jeff May 11 '17 at 18:03
  • Steve: what would you suggest I name `myValue` instead? I can find even worse examples in the .NET reference source: https://referencesource.microsoft.com/#System.Drawing/commonui/System/Drawing/Size.cs,68 – Jeff May 11 '17 at 18:07
  • See, once upon a time we didn't have automagical properties, we had to make a `private string _myValue` and a `public string MyValue{get...}` and in our constructor we did `_myValue = myValue`. And intellisense was a pig that did a `string.StartsWith` not a `string.Contains`. Ahh.. I miss the good ole days – Caius Jard May 11 '17 at 18:10
  • 1
    @Steve it is a common convention (for fields and properties for example) and although I personally do not like and do not use it - it's not surprising at all. – Evk May 11 '17 at 19:02
  • We are free to write code as we like. It is not a life or death problem. It is just bad code. – Steve May 11 '17 at 19:14
  • I've updated the question with a less sinful example that I believe better shows the problem -- I type the identifier in _exactly_ the case I want, and it's still being auto-completed to something else. – Jeff May 11 '17 at 22:09
  • I'd love to know how come someone posts virtually the same answer as I did, nearly half a day later, and theirs is the accepted answer? – Caius Jard May 17 '17 at 20:06

3 Answers3

6

I agree. Here's what I wrote on the issue.

PLEASE make intellisense case-aware. When I type myV it should select myValue instead of MyValue. When I type Myv it should select MyValue instead of myValue.

Here's the kicker: When a user bothers to use the shift key to capitalize a letter, they want the variable or member that HAS that letter capitalized. I'd die of joy if you guys can make this happen. PLEASE.

bboyle1234
  • 4,859
  • 2
  • 24
  • 29
1

I think you may be mistaken about visual studio's selection behaviour: In my experience, Visual Studio case insensitively selects the one I last used, or the first in a list if no use has occurred, by default.

If i typed myv in your case, never having written it before, it would default to the MyValue (first in the list).

If i select the second one down ( myvalue) and then immediately write = myv VS will suggest I mean myValue the second time because I used myValue first time..

That said, one thing I'm certain I've never seen: case sensitive intellisense, and definitely not "case sensitive first char, insensitive other chars" intellisense..

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
1

For your first example, I tested it on my local side and the result is as the following screenshot, I found the pre-selected completion list is depends on “Most recently used members”, please check this: Visual C# IntelliSense enter image description here

IntelliSense remembers the members that you have recently selected in the pop-up List Members box for automatic object name completion. The next time you use Member List, the most recently used members are shown at the top.

For your second example, I got the same result as yours. Since we tried to type code into ‘()’ and I assume the VS filtered completion list per some specific rules or principles, which we can also find the rules from the above documents.

If you have some suggestions or idea about this intellisense, please go to Help-Send Feedback-Provide a suggestion… to share it to the VS Product Team, they are willing to hear different suggestions and user voices.

Sara Liu - MSFT
  • 6,007
  • 1
  • 21
  • 27