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
Titre:
Comparing byte arrays does not work
Divers
Thread ID:
01489235
Message ID:
01489235
Vues:
91
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
Semper ubi sub ubi.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform