【发布时间】:2011-08-18 11:26:20
【问题描述】:
我不小心跳进去了,不知道为什么会这样
string sample = "Hello World";
if (sample.Contains(string.Empty))
{
Console.WriteLine("This contains an empty part ? at position " + sample.IndexOf(string.Empty));
Console.WriteLine(sample.LastIndexOf(string.Empty));
Console.WriteLine(sample.Length);
}
输出
This contains an empty part ? at position 0
10
11
我对最后一部分很满意,但我不知道为什么这被评估为真的。甚至 Indexof 和 LastIndexOf 也有不同的值。
谁能帮我看看为什么会这样?
编辑
我相信这与我的问题有点相关,并且对那些偶然发现这个问题的人也有帮助。
【问题讨论】:
标签: c# contains string-comparison string