473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why return false?

yxq
In VB2005.

Dim a() As Object = {10, 4}
Dim b() As Byte = {10, 4}
MessageBox.Show(a.Equals(b))

Why return False, but not Ture?
Thank you
Oct 13 '06 #1
4 1705
It compares the object not the array content. As this is two different
object, it returns false...

--
Patrice

"yxq" <ga***@163.neta écrit dans le message de news:
Om**************@TK2MSFTNGP04.phx.gbl...
In VB2005.

Dim a() As Object = {10, 4}
Dim b() As Byte = {10, 4}
MessageBox.Show(a.Equals(b))

Why return False, but not Ture?
Thank you

Oct 13 '06 #2
yxq
How to compare the object and array like below?

"Patrice" <sc****@chez.comдÈëÏûÏ¢ÐÂÎÅ:u2**************@TK2M SFTNGP03.phx.gbl...
It compares the object not the array content. As this is two different
object, it returns false...

--
Patrice

"yxq" <ga***@163.neta écrit dans le message de news:
Om**************@TK2MSFTNGP04.phx.gbl...
>In VB2005.

Dim a() As Object = {10, 4}
Dim b() As Byte = {10, 4}
MessageBox.Show(a.Equals(b))

Why return False, but not Ture?
Thank you



Oct 14 '06 #3
I don't know of an automated way, so you'll probably have to write your
own method (someone please correct me if I'm wrong). First check the
number of dimensions, as a one dimensional array can't equal a three
dimensional array, and then I would compare the lengths of both arrays.
Then you probably have to check each member of the array. By the way,
why do you need to check equality of arrays?

Thanks,

Seth Rowe
yxq wrote:
How to compare the object and array like below?

"Patrice" <sc****@chez.comдÈëÏûÏ¢ÐÂÎÅ:u2**************@TK2M SFTNGP03.phx.gbl...
It compares the object not the array content. As this is two different
object, it returns false...

--
Patrice

"yxq" <ga***@163.neta écrit dans le message de news:
Om**************@TK2MSFTNGP04.phx.gbl...
In VB2005.

Dim a() As Object = {10, 4}
Dim b() As Byte = {10, 4}
MessageBox.Show(a.Equals(b))

Why return False, but not Ture?
Thank you
Oct 14 '06 #4
yxq,
In addition to the other comments.

2 problems:

First you are comparing a byte array to an object array, due to the fact you
have 2 distinct kinds of arrays they won't compare.

Second Object.Equals(Object) is a virtual (Overridable) method, allowing
types that have "identity" to override the method & offer an implementation.
Such types include Integer, String, DateTime...

Array does not override this method, as arrays don't have "identity" (in
select cases, such as yours, they may; but overall they don't). Instead
relying on the Object.Equals(Object) implementation.

Object.Equals(Object) itself does a Object.ReferenceEquals which compares
the two object references, not the content of said objects.

As Rowe suggests you will need to write your own function. I would consider
making such a function a Generic Function... However with having 2 distinct
types of arrays this makes a generic function problematic.

Here is a simply Generic ArrayEquals for VS 2005 (.NET 2.0):

Public Function ArrayEquals(Of T)(ByVal a() As T, ByVal b() As T) As
Boolean
If a.GetLowerBound(0) <b.GetLowerBound(0) Then Return False
If a.GetUpperBound(0) <b.GetUpperBound(0) Then Return False
Dim comparer As EqualityComparer(Of T) = EqualityComparer(Of
T).Default
For index As Integer = a.GetLowerBound(0) To a.GetUpperBound(0)
If Not comparer.Equals(a(index), b(index)) Then Return False
Next
Return True
End Function

It requires both parameters to be 1 dimension arrays.

--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"yxq" <ga***@163.netwrote in message
news:Om**************@TK2MSFTNGP04.phx.gbl...
In VB2005.

Dim a() As Object = {10, 4}
Dim b() As Byte = {10, 4}
MessageBox.Show(a.Equals(b))

Why return False, but not Ture?
Thank you
Oct 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: philjhanna | last post by:
Hi I'm having a problem applying return false to a div via addEventListener. I'm adding this so that I can drag (click-hold-move) over an image. (Its so that I can add zooming to the image)...
10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
12
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. ...
8
by: Peter Afonin | last post by:
Hello, I'm using Javascript in ASP.NET application to check whether at least one checkbox in datagrid has been checked. If validation fails, the user gets a warning. If he clicks OK, the form is...
1
by: prashanth023 | last post by:
Hi, This is prashanth kumar. I am getting error , i am gettign number of records using ajax. Please solve this if n >0 i am putting return false in response function. but form is going to...
13
by: cppquester | last post by:
A colleague told me that there is a rule about good stype that a function in C++ should have only one point of return (ie. return statement). Otherwise there might be trouble. I never heard about...
7
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function...
6
by: exander77 | last post by:
I am quite new to c++, about half of a year. I juct wonder, why such code is not possible: int chlen(char * ar) { for(int i=0;ar||return i;i++); } In my opinion, it would be much "cuter"...
6
KoreyAusTex
by: KoreyAusTex | last post by:
If anyone can help me figure out the what the missing return statements are, I think it might be the fact that I need to add a return false in the getValue()? import java.util.*; public class...
0
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm using a URLRewrite module to redirect certain URLs in my .net 2.0 website. However I am getting som really bizarre behaviour public void UrlRewriter_BeginRequest(object sender,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.