Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Comparing byte arrays does not work
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01489235
Message ID:
01489247
Vues:
44
>Considder the code below:
>
>			byte[] one = new byte[] { 0, 1, 2, 3, 4 };
>			byte[] two = new byte[] { 0, 1, 2, 3, 4 };
>
>			if (one != two)
>			{
>				MessageBox.Show("DIFFERENT", "COMAPARE");
>			}
>			else
>			{
>				MessageBox.Show("SAME", "COMAPARE");
>			}
>
>			///////
>
>			bool different = false;
>			for (int i = 0; i < one.Length; i++)
>			{
>				if (one[i] != two[i])
>				{
>					different = true;
>					break;
>				}
>			}
>			if (different)
>			{
>				MessageBox.Show("DIFFERENT", "LOOP");
>			}
>			else
>			{
>				MessageBox.Show("SAME", "LOOP");
>			}
>
>
>Just checking for non-equality (!=) says the byte arrays are different, if I loop though all the elements I find that the byte arrays are the same. I am trying to come up with a good reason why it was implemented like this. Any help is appreciated.
>
>Wow it has been long since I have been on UT.
>
>Einar



As far as I know - that is the default implementation
You are just comparing two objects using object.Equals(). That only returns true if the objects are the same object, ie two pointers pointing to the same object
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform