我有Visual Studio 2015和最新版本的Reshaper(9.1.2).
我倾向于使用一种引用类型和类型别名的方式,就像这个答案所描述的那样.我喜欢使用类型别名进行变量声明的一般外观,并使用System类型来表示该类型存在的静态函数.
举个例子:
string greet = String.Format("Hello {0}!", place);
Run Code Online (Sandbox Code Playgroud)
话虽如此,我在我的IDE中看到一个Roslyn Code Fix来替换String for string.

它要求简化......
我想知道这种变化会影响什么,为什么.
考虑以下代码片段:
var sorted = new[] { "-1.0", "0.0", "1.0", "1.1", "2.0" }
.OrderBy (s => s)
.ToArray ();
Console.WriteLine (string.Join (", ", sorted));
Run Code Online (Sandbox Code Playgroud)
在我的系统上打印
0.0, 1.0, -1.0, 1.1, 2.0
Run Code Online (Sandbox Code Playgroud)
鉴于Ascii代码-小于我预期的数字'ascii代码-1.0, 0.0, 1.0, 1.1, 2.0.
这肯定让我困惑,为什么-1.0是之间 1.0和1.1.那两个以相同的char开头,所以它们之间的任何东西都应该以a开头1.
我隐约怀疑文化或场所设置会影响这一点,但我的(一些德语和很多英语的混合物)在上述情况下可能与英语或Invariant没有区别.
我一直在编写String.IsNullOrEmpty多年,在Visual Studio 2015中,IDE建议将它重构为string.IsNullEmpty,为什么?你会怎么做?
我很清楚String和string后面的内容,但是,我只是想知道为什么VS 2015能给我一个我不需要的提示.
请查看这两个小例子:
public struct Struct
{
public readonly string StringValue;
public readonly int IntValue;
public Struct(string stringValue)
{
this.StringValue = stringValue;
this.IntValue = this.StringValue.GetHashCode(); // Just ignore this assignment, please :).
}
}
public class Class
{
public readonly string StringValue;
public readonly int IntValue;
public Class(string stringValue)
{
this.StringValue = stringValue;
this.IntValue = this.StringValue.GetHashCode(); // Just ignore this assignment, please :).
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,如果我将 struct 作为参数传递,它将制作它的副本someObject.Method(this.cachedStruct);- 这反过来将制作 a 的副本,StringValue因为strings 是不可变的,它将在内存中为该字符串分配数组,这是非常昂贵的操作 [请原谅我,如果我犯了一个错误,请在这种情况下纠正我]。
因此,在这种情况下,我认为使用 的实例Class …
我无法在任何地方找到这些信息,但我确信这只是一个简单的答案.它们可以互换吗?
可能重复:
String和string之间有什么区别
我正在使用string变量,就像这样
string myString = "test";
Run Code Online (Sandbox Code Playgroud)
String如果我想使用类字符串的某些方法(?),我正在使用
String.Format...
Run Code Online (Sandbox Code Playgroud)
我觉得这样看起来更好.买一些人正在做的事情
String myString;
string.Format...
Run Code Online (Sandbox Code Playgroud)
它的工作.但我不喜欢这个.我怎么能告诉他们停下来?对于像这样的东西,有"C#规则"吗?同样的事情int,Int; char,Char; ...
C#中string.Empty和String.Empty有什么区别?还要注意颜色是不同的.它们都引用或类型为System.String类

以下代码无法使用Cannot implicitly convert type 'string' to 'String'C#中的错误进行编译.
void Main()
{
Console.Write("Hello".Append("Mark"));
}
public static class Ext
{
public static String Append<String>(this String str, String app)
{
return str + " " + app;
}
}
Run Code Online (Sandbox Code Playgroud)
您可以通过扩展方法去除类型参数修正编译错误,但我不知道为什么这个不能编译因为typeof(string) == typeof(String)计算结果为true.
以下也适用:
void Main()
{
Console.Write("Hello".Append("Mark"));
}
public static class Ext
{
public static string Append<String>(this String str, string app)
{
return str + " " + app;
}
}
Run Code Online (Sandbox Code Playgroud) 从VS2013升级到VS2017时,我导入了以前的环境设置,但我遇到了奇怪的编辑器行为,其中"String"一词不断变暗:
当使用小写字母时,关键字"string"正确着色.
要清楚,它使用的是正确的颜色,也就是输入类名而不是关键字时所期望的颜色.但由于某种原因,它的调暗方式与调暗不需要的"使用"语句或无法访问的代码的方式相同.
据推测,修复是在选项>文本编辑器> C#某处,但我似乎无法找到它.