Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit d5a8825

Browse files
committed
System.IO: String.Compare -> String.Equals
Per the Best Practices for Using Strings at http://msdn.microsoft.com/en-us/library/dd465121(v=vs.110).aspx * Use an overload of the String.Equals method to test whether two strings are equal. * Use the String.Compare and String.CompareTo methods to sort strings, not to check for equality.
1 parent 211499a commit d5a8825

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/System.IO.FileSystem/src/System/IO/Directory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,12 @@ public static void Move(String sourceDirName, String destDirName)
578578

579579
StringComparison pathComparison = PathInternal.GetComparison();
580580

581-
if (String.Compare(sourcePath, destPath, pathComparison) == 0)
581+
if (String.Equals(sourcePath, destPath, pathComparison))
582582
throw new IOException(SR.IO_SourceDestMustBeDifferent);
583583

584584
String sourceRoot = Path.GetPathRoot(sourcePath);
585585
String destinationRoot = Path.GetPathRoot(destPath);
586-
if (String.Compare(sourceRoot, destinationRoot, pathComparison) != 0)
586+
if (!String.Equals(sourceRoot, destinationRoot, pathComparison))
587587
throw new IOException(SR.IO_SourceDestMustHaveSameRoot);
588588

589589
FileSystem.Current.MoveDirectory(fullsourceDirName, fulldestDirName);

src/System.IO.FileSystem/src/System/IO/DirectoryInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,13 @@ public void MoveTo(String destDirName)
418418
fullSourcePath = FullPath + PathHelpers.DirectorySeparatorCharAsString;
419419

420420
StringComparison pathComparison = PathInternal.GetComparison();
421-
if (String.Compare(fullSourcePath, fullDestDirName, pathComparison) == 0)
421+
if (String.Equals(fullSourcePath, fullDestDirName, pathComparison))
422422
throw new IOException(SR.IO_SourceDestMustBeDifferent);
423423

424424
String sourceRoot = Path.GetPathRoot(fullSourcePath);
425425
String destinationRoot = Path.GetPathRoot(fullDestDirName);
426426

427-
if (String.Compare(sourceRoot, destinationRoot, pathComparison) != 0)
427+
if (!String.Equals(sourceRoot, destinationRoot, pathComparison))
428428
throw new IOException(SR.IO_SourceDestMustHaveSameRoot);
429429

430430
FileSystem.Current.MoveDirectory(FullPath, fullDestDirName);

0 commit comments

Comments
 (0)