4
Answers

linq avoiding foreach loop

Photo of Nagendra Panyam

Nagendra Panyam

6y
746
1
 can any one say how to avoid foreach loop  because drive letter is compared to all drives ithink its laggs my application
 
 
public static bool IsDriveReady(char driveLetter)
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo driveInfo in allDrives)
{
char drive = driveInfo.Name.ToUpper(CultureInfo.InvariantCulture)[0];
if (drive.CompareTo(driveLetter) == 0)
{
return driveInfo.IsReady;
}
}
return false;
}

Answers (4)