C# · 12月 29, 2021

c# – 代表的@前缀是否具有特殊含义?

几次我看到ReSharper生成的代码如下所示: delegate void myHandler(int i);myHandler myHandlerContainer;…foreach (Delegate @delegate in myHandlerContainer.GetInvocationList()){…}


解决方法 MSDN的更多细节:

The prefix “@” enables the use of
keywords as identifiers,which is
useful when interfacing with other
programming languages. The character @
is not actually part of the
identifier,so the identifier might be
seen in other languages as a normal
identifier,without the prefix. An
identifier with an @ prefix is called
a verbatim identifier. Use of the @
prefix for identifiers that are not
keywords is permitted,but strongly
discouraged as a matter of style.

从C# Language Specification: 2.4.2 Identifiers.




Identifiers containing two consecutive underscore characters (U+005F) are reserved for use by the implementation. For example,an implementation might provide extended keywords that begin with two underscores.