Clearest way to declare a char value containing a single quote/apostrophe

前端 未结 6 1287
庸人自扰
庸人自扰 2021-01-07 16:22

To declare a char value in C# we just surround the character with single quotes: \'x\'.

But what is the \"clearest\" way to declare a char value that

相关标签:
6条回答
  • 2021-01-07 16:58

    I think you're looking for '\''

    0 讨论(0)
  • 2021-01-07 17:10

    I guess it's a matter of personal preference, I find escaping it clearest, eg:

    char c = '\'';
    
    0 讨论(0)
  • 2021-01-07 17:11

    You could always just try:

     char c = '\'';
    
    0 讨论(0)
  • 2021-01-07 17:16

    For a char I would use

    myChar = '\'';
    

    The backslash is the standard escape key in both strings and characters, and most people should be able to understand this just fine.

    0 讨论(0)
  • 2021-01-07 17:17

    You can also use '\'' or (char)39

    0 讨论(0)
  • 2021-01-07 17:24

    You can escape the quote with a backslash: '\''

    0 讨论(0)
提交回复
热议问题