mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-04-22 14:02:50 +08:00
33 lines
779 B
C#
33 lines
779 B
C#
namespace NSExt.Extensions;
|
|
|
|
/// <summary>
|
|
/// IntExtensions
|
|
/// </summary>
|
|
public static class IntExtensions
|
|
{
|
|
/// <summary>
|
|
/// 判断枚举是否包含某个位
|
|
/// </summary>
|
|
public static bool HasFlag<T>(this int me, T flag)
|
|
where T : Enum
|
|
{
|
|
return ((long)me).HasFlag(flag);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成随机数
|
|
/// </summary>
|
|
/// <param name="me">大于等于[0],小于[1]</param>
|
|
public static int Rand(this int[] me)
|
|
{
|
|
return new Random(Guid.NewGuid().GetHashCode()).Next(me[0], me[1]);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换成ipv4
|
|
/// </summary>
|
|
public static string ToIpV4(this int me)
|
|
{
|
|
return string.Join(".", BitConverter.GetBytes(me).Reverse());
|
|
}
|
|
} |