c#标准库目前有一个Char.IsSymbol
方法here。
有人对我如何实施Char.IsCurrencySymbol
方法有任何建议吗?
Char.IsCurrencySymbol('$')
// true
Char.IsCurrencySymbol('@')
//false
答案 0 :(得分:10)
像这样:
public static class Extensions
{
public static bool IsCurrencySymbol(this char c)
{
return char.GetUnicodeCategory(c) == UnicodeCategory.CurrencySymbol;
}
}
用法:
bool yes = '$'.IsCurrencySymbol();
bool no = '@'.IsCurrencySymbol();