Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Comparing byte arrays does not work
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01489235
Message ID:
01489247
Views:
43
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform