V4V*_*tta 9 c# string contains string-comparison
我不小心跳进了这个,并且不知道为什么会这样
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);
}
Run Code Online (Sandbox Code Playgroud)
产量
This contains an empty part ? at position 0
10
11
我很满意最后一部分,但我不知道为什么这被评估为真.甚至Indexof
并且LastIndexOf
具有单独的值.
任何人都可以帮我解决这个问题的原因吗?
编辑
我相信这与我的问题有点相关,也会对那些偶然发现这个问题的人有所帮助.
看到这个SO链接:为什么"abcd".StartsWith("")返回true?