DirectoryInfo dInfo = new DirectoryInfo(path)
DirectoryInfo[] directoryInfos = dInfo.GetDirectories();
How can i iterate directoryInfos and select the newest folder?
am looking for the NAME of the newest folder
2 つの方法のうちの 1 つ - どちらが「最適」かはわかりません:
var newest1 = directoryInfos.FirstOrDefault(di => di.CreationTime == directoryInfos.Max(d => d.CreationTime));
また
var newest2 = directoryInfos.OrderByDescending(di => di.CreationTime).FirstOrDefault();
var folder = (directoryInfos の d から orderby d.CreationTime 降順で選択 d).First();
もちろん、他の答えはより高速です:)
DateTime DD = directoryInfos.Max(x=> x.CreationTime);
string[] ss = directoryInfos.Where(x=> x.CreationTime == DD).Select(x=> x.Name).ToArray();
同じ最新の作成時刻を持つ複数のフォルダーが存在する可能性があるため、配列