Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Roslyn Code Fixes with type alias "string" - Visual Studio 2015 [duplicate]

I have Visual Studio 2015 with the latest version of Reshaper (9.1.2).

I tend to use a style of referring to Types and type aliases much the way this answer describes. I like the general look of making variable declarations with the type alias and using the System type for expressing static functions that exist for the type.

As an example:

string greet = String.Format("Hello {0}!", place);

With that said, I'm seeing a Roslyn Code Fix in my IDE to replace String for string. Before Roslyn improvement

It asks to simplify...

Roslyn Simplify name 'String'

And it comes out changing only the String to string:'String' changed to 'string'

I want to what this change affects, and why.

  • Is it a performance improvement in compilation only?
  • Does it add some minor speed benefits at runtime?
  • Is there any other reason why I should care about this code improvement?
like image 873
Zachary Dow Avatar asked Apr 27 '26 08:04

Zachary Dow


1 Answers

So, even now in the latest version of Visual Studio (2015) and the .NET (4.6) framework, string is still just an alias for String. It's simply a style suggestion from Visual Studio.

For anyone else who may want to remove this code style...

This setting can be turned off under: Tools => Options... => Text Editor => C# => Code Style => Prefer intrinsic predefined type keyword in member access expresssions.

Setting visual

like image 141
Zachary Dow Avatar answered May 01 '26 06:05

Zachary Dow