473,662 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compare 2 arrays ?

Is there anything built into .NET that is good (or rather easy) at comparing
?

I have some data (in an array). I make a copy of this array, and the user
changes some of the data, or maybe he doesn't. Then he clicks a button and
my code runs.

So now I want to see if the user made some changes to the data in the array,
or if the user just looked at the data.

I could write some code that loops through the arrays, but is there some
easier solution ?
Like populating 2 datatables. Can they be compared ? Or convert them to XML
docs... anything that can compare 2 xml docs ?

/jim
Aug 15 '06 #1
4 3286
Hi Jim,

One loop ought to be enough, which is easier than populating DataTables
anyway, or compare XML. Or you could create a comparing class and use
that when comparing, but in the end the loop might be best.

for(int i = 0; i < list.Length; i++)
if( ((class)list[i]).CompareTo(lis t2[i]) != 0 )
// change

On Tue, 15 Aug 2006 11:17:57 +0200, Jim Andersen <no****@nospam. dkwrote:
Is there anything built into .NET that is good (or rather easy) at
comparing
?

I have some data (in an array). I make a copy of this array, and the user
changes some of the data, or maybe he doesn't. Then he clicks a button
and
my code runs.

So now I want to see if the user made some changes to the data in the
array,
or if the user just looked at the data.

I could write some code that loops through the arrays, but is there some
easier solution ?
Like populating 2 datatables. Can they be compared ? Or convert them to
XML
docs... anything that can compare 2 xml docs ?

/jim



--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 15 '06 #2
What are these arrays of (what type)?

"Jim Andersen" wrote:
Is there anything built into .NET that is good (or rather easy) at comparing
?

I have some data (in an array). I make a copy of this array, and the user
changes some of the data, or maybe he doesn't. Then he clicks a button and
my code runs.

So now I want to see if the user made some changes to the data in the array,
or if the user just looked at the data.

I could write some code that loops through the arrays, but is there some
easier solution ?
Like populating 2 datatables. Can they be compared ? Or convert them to XML
docs... anything that can compare 2 xml docs ?

/jim
Aug 15 '06 #3
David Jessee wrote:
What are these arrays of (what type)?
I actually start out by having the data in 2 datatables. One column is
system.string the other is system.byte

/jim

Aug 18 '06 #4
Doing this type of comparison is always a little awkward. Effectively,
you're trying to see if, given 2 sets, whether the intersection of the two
sets is identical to both sets individually (I'm thinking in terms of Venn
Diagrams here). I don't know if the elements of each set have to be in the
same order or not. Generally, when dealing with sets as an abstract concept,
its not an issue.

Given that: I've read 3 or 4 different ways that this cam be acomplished.
None of then are really as efficient as I think we'd all like for them to be
because you have to do a member by member comparison of each element in the
sets..here's the one I use in .NET..

Lets say I have 2 Sets A and B (Collections, Arrays, or some other class
that implements an aggregation)

1) if the sets have different numbers of items, the sets are not equal.
2) create an Int32 array (arrA) the same size as Set A
3) Populate the Array with the Hash Codes of all of the members of Set A
4) For each member of Set B
a) get the member's HashCode
b) Do a BinarySearch of arrA to see if there's a matching Hash Code
c) if there is not, then the sets are not equal
5) if you got through step 4 without any problems, then the sets must be
equal (you already checked to see if the sets were of the same size)

Granted, I always override GetHashCode on the classes I create, so I know
that the hases will correctly Reflect state equivelance in my classes.

"Jim Andersen" wrote:
David Jessee wrote:
What are these arrays of (what type)?

I actually start out by having the data in 2 datatables. One column is
system.string the other is system.byte

/jim

Aug 18 '06 #5

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

Similar topics

0
2705
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2: The name of the second array $formField1CompareWith: String to use as my comparison basis for first array. Defaults to using $val unless it's 'key' $formField2CompareWith: String to use as my comparison basis for second array. Same default as...
4
5121
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows for each record, each row accounts for a different type of outcome I'm having trouble with MySQL date comparison. I'm looking for some kind of query that will compare the all date column and only give me the latest date. Then once I have it, ...
5
2991
by: Jim H | last post by:
I will have many 3 byte Byte arrays. Is there a way to compare the values without iterating through and comparing each element in the code? Example: byte lTest1 = new byte {0x1, 0x2, 0x3}; byte lTest2 = new byte {0x1, 0x2, 0x3}; byte lTest3 = new byte {0x1, 0x5, 0x3}; if(Comparer.Equals(lTest1, lTest2)) System.Diagnostics.Trace.WriteLine("Test1 and Test2 are the same", "Debug");
2
16351
by: nobs | last post by:
Hi I have two byte arrays (each with a length of 8 bytes) an I'd like to compare them if they are equal. The operator == shouldn't work because its not a basic Data Type so I used the method Equal, but it also isn't working. right know I use if(mykey.Length!= keytocheck.Length)
2
11324
by: Tom | last post by:
What's the best way to compare two byte arrays? Right now I am converting them to base64 strings and comparing those, as so: 'result1 and result2 are two existing byte arrays that have been loaded Dim data64_1 As String = System.Convert.ToBase64String(result1, 0, result1.Length) Dim data64_2 As String = System.Convert.ToBase64String(result2, 0, result2.Length) Debug.WriteLine(IIf(data64_1 = data64_2, "Equals", "NOT Equals"))
8
3395
by: Turbot | last post by:
Hello, Anyone know how to compare two byte arrays without going through each item in the array. I actually want to compare two bitmap objects to see if they both contain the same picture bit have been unable to do this. I figured if I converted them to byte arrays there would be a simple way of comparing them but I have had no luck. Thanks in advance.
4
1988
by: Justin Emlay | last post by:
I have two lists. These can be in either table form or array. That is, my data is in a dataset which I can move to an array if need be. ListA is a master list and it contains all items. ListB contains the same items but not necessarily all the items. I need to know which items are missing. I remember messing with a compare array function but now I can't seem to find it anywhere. Ideas? I would rather NOT loop through each item in...
5
40090
by: Oleg Subachev | last post by:
Is there other way of comparing two byte arrays than iterating through the two and compare individual bytes ? Oleg Subachev
3
2891
by: =?Utf-8?B?UmljY2FyZG8=?= | last post by:
What is the best method to compare 2 array to knw if each element is equal? Now, i have to compare the datarow.itemarray of 2 datarows wich is equals in structure. I tried to write this routine: (OPTION STRICT MUST BE ON!!) Private Function ISArrayEquals(ByVal A As Array, ByVal B As Array) As Boolean For index As Integer = 0 To A.Length - 1 If A.GetValue(index) <B.GetValue(index) Then '<----Here is the error! Return False End If
0
38198
gits
by: gits | last post by:
This little article will show you how to optimize runtime performance when you need to compare two arrays (a quite common task). Have a close look at the entire article, and you will see the advantage of the final code snippet :) Let's assume we want to find out the element that is contained by both of the lists. var list1 = ; var list2 = ; for (var i in list1) { for (var j in list2) {
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.