FileInfo - Equals

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I just want to check something. I have two objects of FileInfo.
FileInfo f1 = new FileInfo(“sam.exeâ€);
FileInfo f2 = new FileInfo(“sam.exeâ€);

If I use the f1.Equals(f2); it gives false but I want true because it’s the same file. What should I do? I want that when I call Equals, it use the FullName property to check. Should I create a new class? Thanks.
 
Hi,
I just want to check something. I have two objects of FileInfo.
FileInfo f1 = new FileInfo("sam.exe");
FileInfo f2 = new FileInfo("sam.exe");

If I use the f1.Equals(f2); it gives false but I want true because
it's the same file. What should I do? I want that when I call Equals,
it use the FullName property to check. Should I create a new class?

The two objects are different (it's two _different_ objects just _pointing_
to the same file). You'll need to check the filename.

Regards,

Frank Eller
www.frankeller.de
 
For my FileInfo to have a different Equals function I decided to extend it and override the Equals method to my desire but the compiler refuses and says that it’s a sealed class. What should I do? As I said, I want all the functions of FileInfo and have the Equals function behave differently based on FullName. What should I do?
 
Sam said:
For my FileInfo to have a different Equals function I decided to
extend it and override the Equals method to my desire but the
compiler refuses and says that it?s a sealed class. What should I do?
As I said, I want all the functions of FileInfo and have the Equals
function behave differently based on FullName. What should I do?

You can't, basically. What you *can* do is have a class which
*contains* a FileInfo instead (and could provide all the functionality
that FileInfo does, just by proxying calls) and override Equals on that
instead.
 
Back
Top