public sealed class DriveInfo { [DllImport("kernel32.dll", EntryPoint = "GetDiskFreeSpaceExA")] private static extern long GetDiskFreeSpaceEx(string lpDirectoryName, out long lpFreeBytesAvailableToCaller, out long lpTotalNumberOfBytes, out long lpTotalNumberOfFreeBytes);
public static long GetInfo(string drive, out long available, out long total, out long free) { return GetDiskFreeSpaceEx(drive, out available, out total, out free); }
public static DriveInfoSystem GetInfo(string drive) { long result, available, total, free; result = GetDiskFreeSpaceEx(drive, out available, out total, out free); return new DriveInfoSystem(drive, result, available, total, free); } }
public struct DriveInfoSystem { public readonly string Drive; public readonly long Result; public readonly long Available; public readonly long Total; public readonly long Free;
public DriveInfoSystem(string drive, long result, long available, long total, long free) { this.Drive = drive; this.Result = result; this.Available = available; this.Total = total; this.Free = free; } }
可以通过
DriveInfoSystem info = DriveInfo.GetInfo("c:");来获得指定磁盘的开销情况
11.如何获得不区分大小写的子字符串的索引位置
1)通过将两个字符串转换成小写之后使用字符串的IndexOf方法:
string strParent = "The Codeproject site is very informative.";
string strChild = "codeproject";
// The line below will return -1 when expected is 4. int i = strParent.IndexOf(strChild);
// The line below will return proper index int j = strParent.ToLower().IndexOf(strChild.ToLower());
string strParent = "The Codeproject site is very informative.";
string strChild = "codeproject"; // We create a object of CompareInfo class for a neutral culture or a culture insensitive object CompareInfo Compare = CultureInfo.InvariantCulture.CompareInfo;
int i = Compare.IndexOf(strParent,strChild,CompareOptions.IgnoreCase);