为什么“abcd".StartsWith(“") 返回true? [英] Why does "abcd".StartsWith("") return true?
问题描述
标题是整个问题.有人能告诉我为什么会发生这种情况吗?
Title is the entire question. Can someone give me a reason why this happens?
推荐答案
是的 - 因为它确实以空字符串开头.实际上,空字符串在逻辑上出现在每对字符之间.
Yes - because it does begin with the empty string. Indeed, the empty string logically occurs between every pair of characters.
这样说吧:你能给开始于"的什么定义排除这种情况?这里有一个简单的开始于"的定义,但没有:
Put it this way: what definition of "starts with" could you give that would preclude this? Here's a simple definition of "starts with" that doesn't:
"如果 x 的第一个 y.Length
字符与 y 匹配,则 x 以 y 开头."
"x starts with y if the first y.Length
characters of x match those of y."
替代(等效)定义:
"如果 x.Substring(0, y.Length).Equals(y)
,则 x 以 y 开头"
"x starts with y if x.Substring(0, y.Length).Equals(y)
"
这篇关于为什么“abcd".StartsWith(“") 返回true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!