Nagendra Panyam

Nagendra Panyam

  • NA
  • 190
  • 17.5k

linq avoiding foreach loop

Feb 19 2019 6:21 AM
 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)