【发布时间】:2025-08-15 04:50:02
【问题描述】:
出于好奇,我只是一个简短的问题。
string str = "string";
Console.WriteLine(str.EndsWith(string.Empty)); //true
Console.WriteLine(str.LastIndexOf(string.Empty) == str.Length); //false
//of course string are indexed from 0,
//just wrote if for fun to check whether empty string get some extra index
///somehow by a miracle:)
//finally
Console.WriteLine(str.LastIndexOf(string.Empty)
== str.LastIndexOf('g')); //true :)
【问题讨论】:
-
你对
string.Empty的概念是什么? 是什么? -
一切都不包含任何东西。无处不在。
-
我的问题是,为什么会有这么多赞成票支持这样一个毫无意义的问题?为什么知道 C# 字符串是否以空字符串结尾很重要?您将如何使用这些有价值的信息?