http://msdn.microsoft.com/en-us/library/1x308yk8.aspxなぜすべてのChar静的な "Is ..."は文字列の過負荷を持っていますか? IsWhiteSpace(string、Int32)?
これは私がこれを行うことができます:
var str = "string ";
Char.IsWhiteSpace(str, 6);
むしろより:
Char.IsWhiteSpace(str[6]);
は珍しいようですので、私は反射を見て:
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static bool IsWhiteSpace(char c)
{
if (char.IsLatin1(c))
{
return char.IsWhiteSpaceLatin1(c);
}
return CharUnicodeInfo.IsWhiteSpace(c);
}
[SecuritySafeCritical]
public static bool IsWhiteSpace(string s, int index)
{
if (s == null)
{
throw new ArgumentNullException("s");
}
if (index >= s.Length)
{
throw new ArgumentOutOfRangeException("index");
}
if (char.IsLatin1(s[index]))
{
return char.IsWhiteSpaceLatin1(s[index]);
}
return CharUnicodeInfo.IsWhiteSpace(s, index);
}
3つのこと私を殴った:
- 上限チェックのみを行うのはなぜですか?
ArgumentOutOfRangeException
を投げて、0より下のインデックスは文字列の標準を与えるでしょうIndexOutOfRangeException
- 私は一般的な話を読んだことがありますが、ここで何をしているのか、また上限チェックにリンクされているかはまだ分かりません。
TargetedPatchingOptOutAttribute
は、他の方法には存在しない。例IsLetter
、IsNumber
など
ああ、いいキャッチ、ありがとう。人々はこれをupvoteする必要があります、それはチェックアウト! 'IL_0015:blt.un.s IL_0022' – weston