我正在查看System.String
,我想知道为什么EndsWith
andStartsWith
方法在它们可以采用的参数方面不是对称的。
具体来说,为什么System.String.EndsWith
支持 char 参数而不支持System.String.StartsWith
?这是因为任何限制或设计特点吗?
// System.String.EndsWith method signatures
[__DynamicallyInvokable]
public bool EndsWith(string value)
[ComVisible(false)]
[SecuritySafeCritical]
[__DynamicallyInvokable]
public bool EndsWith(string value, StringComparison comparisonType)
public bool EndsWith(string value, bool ignoreCase, CultureInfo culture)
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
internal bool EndsWith(char value)
{
int length = this.Length;
return length != 0 && (int) this[length - 1] == (int) value;
}
// System.String.StartsWith method signatures
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
[__DynamicallyInvokable]
public bool StartsWith(string value)
[SecuritySafeCritical]
[ComVisible(false)]
[__DynamicallyInvokable]
public bool StartsWith(string value, StringComparison comparisonType)
public bool StartsWith(string value, bool ignoreCase, CultureInfo culture)