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:
01489254
Vues:
41
>>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.
>
>You're confusing value equality with reference equality. Default comparison is reference.
byte[] copy = two;
>if (copy == two)
>{
>//true;
>}
>
>
>>Wow it has been long since I have been on UT.
>
>True....

Thanks for the replies everyone.
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform