【发布时间】:2014-12-10 15:29:15
【问题描述】:
我知道在 C# 中 string 和 String 之间没有区别(除了为 System.String 添加的 using System)。尽管如此,就像在this SO-answer 中一样,当我调用String.SomeMethod(例如String.IsNullOrWhitespace(...);String.Format(...)或String.Empty。
- 搜索模式:
string.$method$ - 模式严重性:
Show as suggestion - 匹配相似结构:
Unchecked - 搜索说明:
Check if string.SomeMethod is used instead of String.SomeMethod - 替换模式:
String.$method$ - 替换后的格式:
Checked - 缩短参考:
Unchecked - 替换描述:
Use String instead of string
在像string.IsNullOrWhitespace(...) 这样的行上,它确实给出了建议并将其正确替换为String.IsNullOrWhitespace(...)。然而,问题是它现在也给出了建议,当它已经正确或在我替换它之后。那么是否可以使搜索模式区分大小写?所以它只会在string.SomeMethod 给出建议,而不是在String.SomeMethod?
编辑:另外,是否可以选择将其应用于整个项目/解决方案,类似于警告 Remove unused directives in file -> Remove unused directives in solution(在 v8.0 或更高版本中)?
【问题讨论】:
-
"C# 中的字符串和字符串没有太大区别。" - 没有区别。
string是String的别名。 -
@CriketerOnSO 然而,您可以偏好使用其中一种,如果您这样做,最好在整个代码库中保持一致;所以这不是一个不合理的问题。
-
@decPL,我不是说这是一个不合理的问题,我只是指有问题的陈述,(现已被删除)