Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

FileInfo is a stateful reference type, so overriding Equals and GetHashCode to use value equality would be a Bad Idea™.

E.g.:

    var f = new FileInfo("image.jpg");
    var set = new HashSet<FileInfo> { f };
    f.MoveTo("image2.jpg");
    Console.WriteLine(set.Contains(f)); // Would be false (sometimes)


Then FileInfo should not be hashable, so a Set of it could not even be declared.


But the current implementation using reference equality is perfectly valid, and often quite useful.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: