ドライブの情報を取得して並べ替えるにはどうすればよいAvalableFreeSpace
ですか? これが私のコードです:
List<DriveInfo> list = new List<DriveInfo>();
foreach (DriveInfo item in DriveInfo.GetDrives())
{
list.Add(item);
}
ドライブの情報を取得して並べ替えるにはどうすればよいAvalableFreeSpace
ですか? これが私のコードです:
List<DriveInfo> list = new List<DriveInfo>();
foreach (DriveInfo item in DriveInfo.GetDrives())
{
list.Add(item);
}
LINQ を使用OrderBy
- シーケンスの要素をキーに従って昇順に並べ替えます。(MSDN: http://msdn.microsoft.com/en-us/library/bb534966.aspx )
var sortedDrives = DriveInfo.GetDrives().OrderBy(l => l.AvailableFreeSpace).ToList();
LinQ を使用すると、このように並べ替えることができます。をチェックするIsReady
と、例外が防止されます。
var drives = DriveInfo.GetDrives()
.Where(x => x.IsReady)
.OrderBy(x => x.AvailableFreeSpace)
.ToList();