How to check the last character of a string in C#?

后端 未结 3 1211
深忆病人
深忆病人 2021-02-06 23:58

I want to find the last character of a string and then put in an if stating that if the last character is equal to \"A\", \"B\" or \"C\" then to do a certain action

3条回答
  •  不要未来只要你来
    2021-02-07 00:30

    I assume you don't actually want the last character position (which would be yourString.Length - 1), but the last character itself. You can find that by indexing the string with the last character position:

    yourString[yourString.Length - 1]
    

提交回复
热议问题