Bonjour à tous !

Je veux surcharger l'opérateur == pour comparer deux objets de ma classe.

Voilà comment ma classe définie la surcharge des opérateurs == (et != qui doit aller avec) (méthode surcharge opérateur en gras)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83


public class RemoteFileInfo : IRemoteFileInfo
{
	private string[] _filename = new string[2];
    private string _md5;
    private long _weight;


    public RemoteFileInfo()
	{
		//
		// TODO*: ajoutez ici la logique du constructeur
		//
	}
    public RemoteFileInfo(string completeFilename,long weight,string md5)
    {

        _filename = SplitFilenameDirname(completeFilename);
        RemoteFile_Dir = _filename[0];
        RemoteFile_Name = _filename[1];
        RemoteFile_Weight = weight;
        RemoteFile_Md5 = md5;
    }



        private string[] SplitFilenameDirname(string completeFilename)
        {
            string[] result = new string[2];
            char _antislash = '\\';
            int start = completeFilename.LastIndexOf(_antislash) + 1;
            int length = completeFilename.Length - start;
            result[0] = completeFilename.Substring(0,start);
            result[1] = completeFilename.Substring(start,length);
            new Error(new user()).WriteError("tttttt" + result[0] + "\n" + result[1],new Exception());
            return result;
        }
    
public static bool operator== (RemoteFileInfo rmf1,RemoteFileInfo rmf2)
    {
        bool compare_name,compare_weight,compare_md5;
        compare_name = (string.Compare(rmf1.RemoteFile_Name, rmf2.RemoteFile_Name) == 0) ? true : false;
        compare_weight = (rmf1.RemoteFile_Weight == rmf2.RemoteFile_Weight) ? true : false;
        compare_md5 = (string.Compare(rmf1.RemoteFile_Md5, rmf2.RemoteFile_Md5) == 0) ? true : false;
        return (compare_name && compare_weight && compare_md5);
    }

    public static bool operator !=(RemoteFileInfo rmf1, RemoteFileInfo rmf2)
    {
        bool compare_name, compare_weight, compare_md5;
        compare_name = (string.Compare(rmf1.RemoteFile_Name, rmf2.RemoteFile_Name) == 0) ? true : false;
        compare_weight = (rmf1.RemoteFile_Weight == rmf2.RemoteFile_Weight) ? true : false;
        compare_md5 = (string.Compare(rmf1.RemoteFile_Md5, rmf2.RemoteFile_Md5) == 0) ? true : false;
        return !(compare_name && compare_weight && compare_md5);
    }


    //Accesseurs

    public string RemoteFile_Dir
    {
        get { return this._filename[0]; }
        set { this._filename[0] = value; }
    }
    public string RemoteFile_Name
    {
        get { return this._filename[1];}
        set { this._filename[1] = value; }
    }
    public long RemoteFile_Weight
    {
        get { return this._weight; }
        set { this._weight = value; }
    }
    public string RemoteFile_Md5
    {
        get { return this._md5; }
        set { this._md5 = value; }
    }

}
Mais quand je teste deux objets (dont je sais qu'ils sont identiques) comme ceci:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
 
            bool a = (rmf == _U.U_REMOTE_FILE) ? true : false;
            MessageBox.Show(a.toString());
 
//où rmf et _U.UREMOTE_FILE sont deux instances de RemoteFileInfo()
J'obtiens toujours false !

Est-ce qu'il y a une erreur dans les méthode qui surcharge les opérateurs == et != ??
Est-ce que quand je fais rmf == _U.U_REMOTE_FILE , j'utilise bien le == surchargé ???

Merci beaucoup pour votre aide !