Do C# strings end with empty string?

后端 未结 4 1259
再見小時候
再見小時候 2020-12-20 11:47

Just a short question out of curiosity.

string str = \"string\";
Console.WriteLine(str.EndsWith(string.Empty));                  //true
Console.WriteLine(st         


        
4条回答
  •  余生分开走
    2020-12-20 12:13

    Try this:

    string str = "string";
    Console.WriteLine(str.EndsWith(string.Empty));                  //true 
    Console.WriteLine(str.LastIndexOf(string.Empty) == str.Length-1); // true
    Console.ReadLine();
    

    So yes as Oded said, they do always match.

提交回复
热议问题