本文整理汇总了C#中IComparable.TypeSwitch方法的典型用法代码示例。如果您正苦于以下问题:C# IComparable.TypeSwitch方法的具体用法?C# IComparable.TypeSwitch怎么用?C# IComparable.TypeSwitch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IComparable
的用法示例。
在下文中一共展示了IComparable.TypeSwitch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasOneBitSet
public static bool HasOneBitSet(IComparable value)
{
return value.TypeSwitch(
(long v) => HasOneBitSet((long)v),
(ulong v) => HasOneBitSet(unchecked((long)v)),
(int v) => HasOneBitSet((long)v),
(uint v) => HasOneBitSet((long)v),
(short v) => HasOneBitSet((long)v),
(ushort v) => HasOneBitSet((long)v),
(sbyte v) => HasOneBitSet((long)v),
(byte v) => HasOneBitSet((long)v));
}
示例2: Add
private static IComparable Add(IComparable value, uint number)
{
return value.TypeSwitch(
(long v) => unchecked((long)(v + number)),
(ulong v) => unchecked((ulong)(v + number)),
(int v) => unchecked((int)(v + number)),
(uint v) => unchecked((uint)(v + number)),
(short v) => unchecked((short)(v + number)),
(ushort v) => unchecked((ushort)(v + number)),
(sbyte v) => unchecked((sbyte)(v + number)),
(byte v) => unchecked((byte)(v + number)),
_ => (IComparable)null);
}
示例3: GreaterThanOrEqualsZero
private static bool GreaterThanOrEqualsZero(IComparable value)
{
return value.TypeSwitch(
(long v) => v >= 0,
(ulong v) => v >= 0,
(int v) => v >= 0,
(uint v) => v >= 0,
(short v) => v >= 0,
(ushort v) => v >= 0,
(sbyte v) => v >= 0,
(byte v) => v >= 0);
}