1

I am old-fashioned, and prefer "String" (class) to "string" (basic type) in C#. In Visual Studio, Intellisense always substitutes "string" for "String" so that I get things like:

static Dictionary<String, Dictionary<String, Tuple<String, String>>> s_edits = new Dictionary<string,Dictionary<string,Tuple<string,string>>>
                                                                                   __________________________________________________________

where the underlined section was added by Intellisense. Is there any way I can persuade VS to use "String"?

As you can imagine, trying to Google for "String" vs "string" isn't working :-(.

Tom West
  • 1,759
  • 2
  • 13
  • 20
  • Perhaps this will help? http://stackoverflow.com/questions/32187486/why-is-string-considered-a-simplified-version-of-string – Cody Gray - on strike Jul 17 '16 at 18:33
  • I don't get the old-fashioned thing either. Generally, its preferred to use `string` when referring to the object, such as `string s="test";`. When accessing methods from the object, then it should be `String`, such as `String.Format("{0}", "test");` – Icemanind Jul 17 '16 at 18:33
  • You'll have to treat the person that is going to maintain your code some day as a homicidal maniac that knows where you live. This will definitely set him off. – Hans Passant Jul 17 '16 at 19:14
  • As a kinda-sorta rule (since I'm not using many structs), dark blue type means a value type and light blue is a reference type. It's not hard and fast, obviously, but that's how my mind is parsing things. 'string' violates that assumption, causing me to waste a few extra neurons when I have few enough to spare... – Tom West Jul 17 '16 at 20:29
  • 2
    My grandfather always gets on my case about that. He's like a broken record. "When I was your age, we used the `String` class, not some fancy new-fangled `string` type." – Scott Hannen Jul 18 '16 at 02:38
  • Why would you need to worry about details like whether a type is a reference type or a value type, except in rare cases? Certainly this doesn't seem like useful semantic information to always have at the forefront of your mind when writing code. Now, if the IDE was smart enough to highlight types differently that implemented IDisposable, *that* would be worthwhile... – Cody Gray - on strike Jul 18 '16 at 03:15
  • > Certainly this doesn't seem like useful semantic information to always have at the forefront of your mind when writing code. – Tom West Jul 22 '16 at 00:31
  • "Certainly this doesn't seem like useful semantic information to always have at the forefront of your mind when writing code." Seriously? The difference between value and reference types is relevant with every assignment (or comparison)! (Couldn't edit my previous typo'd comment even though it was only a minute!) – Tom West Jul 22 '16 at 00:40

1 Answers1

4

You can actually supress the warning that visual studio shows in 2 ways.

To do that on the project level:

Solution Explorer > Right Click Project > Properties > Build.

Next to Supress Warning, write IDE0001

To do it globally for All projects, you can:

Tools > Options > Text Editor > C# > Code Style > uncheck :

Prefer intrinsic predefined type keyword when declaring locals, parameters and members

Zein Makki
  • 29,485
  • 6
  • 52
  • 63
  • I saw that option and posted it in an answer that is now deleted, but in my testing it did not affect the autocompletion the OP is asking about. Keywords are used for autocompletion regardless of that setting. – Mike Zboray Jul 17 '16 at 18:45
  • @mikez VS doesn't automatically substitute string with String. I have never experienced this. If you write `stri` and pres TAB, you get string. – Zein Makki Jul 17 '16 at 18:47
  • No it doesn't but that is not what the question is. The OP wants "String" to be used by default for autocompletion. Do what you've described in your answer, then type what the OP has in the question and use the autocompletion option in the editor when you reach `new`. It still uses the `string` keyword regardless of that setting. – Mike Zboray Jul 17 '16 at 18:51
  • As mike z pointed out, this is when I use auto-complete after the 'new' keyword, so Intellisense writes out the declaration with the 'string' type keyword. – Tom West Jul 17 '16 at 20:24