Difference between LastIndexOf('string') vs LastIndexOf('string')OrdincalComparison
本问题已经有最佳答案,请猛点这里访问。
两者有什么区别
这个
1 | var ext = name.LastIndexOf(@"."); |
而这
1 | var ext = name.LastIndexOf(@".", System.StringComparison.Ordinal); |
From the
An operation that uses ordinal sort rules performs a comparison based on the numeric value (Unicode code point) of each Char in the string. An ordinal comparison is fast but culture-insensitive. When you use ordinal sort rules to sort strings that start with Unicode characters (U+), the string U+xxxx comes before the string U+yyyy if the value of xxxx is numerically less than yyyy.
额外参数是告诉对比弦的方法。将使用统一码点进行比较。Enum use the culture(instariant or the current one)的其他价值,可以作为无意识比较。