using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace RoadFlow.Utility { public static class MathExtensions { /// /// 判断数字是否在参数里面 /// /// /// /// public static bool In(this int digit, params int[] digits) { return digits.Contains(digit); } /// /// 判断数字不在参数里面 /// /// /// /// public static bool NotIn(this int digit, params int[] digits) { foreach (int i in digits) { if (i == digit) { return false; } } return true; } /// /// 转换为文件大小显示 /// /// /// public static string ToFileSize(this long size) { string fileSize; if(size == 0) { fileSize = "0 KB"; } else if (size < 1024) { fileSize = size + " BT"; } else if (size < 1048576) { fileSize = ((double)size / 1024).ToString("0.00") + " KB"; } else if (size < 1073741824) { fileSize = ((double)size / 1048576).ToString("0.00") + " MB"; } else { fileSize = ((double)size / 1073741824).ToString("0.00") + " GB"; } return fileSize; } } }