问题描述
这句话是什么
返回@;
及何时使用?
What is this statement
return @"";
and when it is used?
推荐答案
return string.Empty;
在这个例子中使用立即常量,在大多数情况下,是一种不好的风格。即使返回
,返回@
和返回string.Empty
是等价的,第一个,特别是第二个变种不是整洁和污染代码。
和'@'只是意味着冗长;它允许使用字符串的多行课程代码并详细处理其他转义的文字(例如\ n),并且表示为双:@这是我的字符串引用里面是相当于这是我的字符串\quote \inside。
顺便说一下,在提出这样的问题之前,你真的需要阅读一些语言手册。
Using immediate constants like in this example, in most cases, is a sign of bad style. Even though return ""
, return @""
and return string.Empty
are equivalent, the first and especially second variants are not neat and contaminate code.
And '@' just means verbosity; it allows to use a multiline course code of the string and treat otherwise escaped literals (such as "\n") verbosely, and " is expressed as double ": @"this is my string with ""quote"" inside" is equivalent to "this is my string with \"quote\" inside".
By the way, before asking such questions, you really need to read some language manual.
这篇关于这句话是什么意思? return @"" ;;什么时候使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!