C# keywords as a variable

前端 未结 4 2109
一向
一向 2020-12-01 23:38

In VB.NET, you can surround a variable name with brackets and use keywords as variable names, like this:

Dim [goto] As String = \"\"

Is the

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 23:44

    Prefix your variable with the @ sign

    string @class = "fred";
    

    The @ sign can also be used to prefix a non-escaped string literal:

    string a = "fred\"; \\ invalid
    string b = @"fred\"; \\ valid. the backslash is part of the literal 'fred\'
    

    I use the latter from time to time but think the using an @ sign to name variables is ugly.

提交回复
热议问题