C# keywords as a variable

前端 未结 4 2090
一向
一向 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.

    0 讨论(0)
  • 2020-12-01 23:54
    string @string = "";
    
    0 讨论(0)
  • 2020-12-02 00:03

    With a @

    public IActionResult Submit(Guid? id, string type, string key, string @event)
    {
    
    }
    
    0 讨论(0)
  • 2020-12-02 00:07

    Yes, prefix it with a @

    String @goto = "";
    
    0 讨论(0)
提交回复
热议问题