I have 2 DirectoryInfo objects and want to check if they are pointing to the same directory. Besides comparing their Fullname, are there any other better ways
Case-insensitive comparison is the best you can get. Extract it to a helper class just in case mankind comes up with a better method.
public static class DirectoryInfoExtensions
{
public static bool IsEqualTo(this DirectoryInfo left, DirectoryInfo right)
{
return left.FullName.ToUpperInvariant() == right.FullName.ToUpperInvariant();
}
}
and use:
if (di1.IsEqualTo(di2))
{
// Code here
}