473,839 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compare Two Structure Data Types...

Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and
Structure B.

Structure A
Public Fname as String
Public LastName as String
Public City as String
Public Zip as String
End Structure
Structrure B
Public Fname as String
Public LastName as String
Public City as String
Public Zip as String
End Structure

How can I compare these two data types.. ie Fname, LastName, City, Zip of
Structure A should match Fname, LastName, City, Zip of Sturcture [shouldn't
be ase sensitive.]

If Sturcture A = Structure Then

Do tthis ..
Else

End if
Thanks in advance.
Nov 21 '05 #1
3 8906
You cannot make a direct comparison between two different types, even if they
are otherwise identical. Since your two structures are set up identically,
you could use one structure instead:

Dim struct1 as New A
dim struct2 as New A

dim n1 as String = "Bill"
din n2 as String = "bill"

struct1.Fname = n1.ToLower
struct2.Fname = n2.ToLower

If struct1.Equal(s truct2) then
messagebox.show ("equal")
end if

Since the Structure is not a simple datatype, you must use equals, rather
than " = ", which you would use for simple data types.

For example, if you had two separate structures, you could compare any
string value in one structure with any string value in another structure
using " = ".

www.charlesfarriersoftware.com
"Kiran B." wrote:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and
Structure B.

Structure A
Public Fname as String
Public LastName as String
Public City as String
Public Zip as String
End Structure
Structrure B
Public Fname as String
Public LastName as String
Public City as String
Public Zip as String
End Structure

How can I compare these two data types.. ie Fname, LastName, City, Zip of
Structure A should match Fname, LastName, City, Zip of Sturcture [shouldn't
be ase sensitive.]

If Sturcture A = Structure Then

Do tthis ..
Else

End if
Thanks in advance.

Nov 21 '05 #2
You have to compare each field by itself. Either write a function that
accept two Structures and then checks and return true or false, or convert
them to classes and make a method that accept the other item and compares
them.

Only way I know how.

Chris
"Kiran B." <kb********@yah oo.com> wrote in message
news:Od******** ******@TK2MSFTN GP10.phx.gbl...
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and
Structure B.

Structure A
Public Fname as String
Public LastName as String
Public City as String
Public Zip as String
End Structure
Structrure B
Public Fname as String
Public LastName as String
Public City as String
Public Zip as String
End Structure

How can I compare these two data types.. ie Fname, LastName, City, Zip of
Structure A should match Fname, LastName, City, Zip of Sturcture [shouldn't be ase sensitive.]

If Sturcture A = Structure Then

Do tthis ..
Else

End if
Thanks in advance.

Nov 21 '05 #3
Kiran,
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and
Structure B. Why two identical structure types, why not a single type with two instances?

Encapsulation, one of the tenants of OO, says that the Structure itself
should know how to compare itself to others of its type.

I normally override & overload the Equals method on the Structure to do the
comparison. With VS.NET 2005 (aka Whidbey, due out later in 2005) you will
be able to overload the equals "=" operator as well. In the case of
Structure A = Structure B, I would overload Equals for the two types...

Dim theA As A
Dim theB As A
If theA.Equals(the B) Then

Do tthis ..
Else

End if
Structure A
Public Fname As String
Public LastName As String
Public City As String
Public Zip As String

Public Overloads Function Equals(ByVal other As A) As Boolean
Return Fname = other.Fname _
AndAlso LastName = other.LastName _
AndAlso City = other.City _
AndAlso Zip = other.Zip
End Function

Public Overloads Overrides Function Equals(ByVal obj As Object) As
Boolean
If TypeOf obj Is A Then
Return Equals(DirectCa st(obj, A))
Else
Return False
End If
End Function

End Structure

You could overload the Equals function a third time if you want to compare
to Structure B also...

Public Overloads Function Equals(ByVal other As B) As Boolean
Return Fname = other.Fname _
AndAlso LastName = other.LastName _
AndAlso City = other.City _
AndAlso Zip = other.Zip
End Function

Dim theA As A
Dim theB As B

If theA.Equals(the B) Then

If I overloaded Equals in A for B, I would also overload Equals in B for A,
so the operation was symmetrical.

Dim theA As A
Dim theB As B

Debug.Assert(th eA.Equals(theB) = theB.Equals(the A), "Symmetrica l Equals
A=B!")

Also if you override Equals, you should consider overriding GetHashCode as
well.

Public Overrides Function GetHashCode() As Integer
Return Fname.GetHashCo de() _
Xor LastName.GetHas hCode() _
Xor City.GetHashCod e() _
Xor Zip.GetHashCode ()
End Function

Overriding GetHashCode allows your structure to be used as a key in a
HashTable, if you use your Structure as a Key, you should make all the
fields immutable (ReadOnly).

Hope this helps
Jay
"Kiran B." <kb********@yah oo.com> wrote in message
news:Od******** ******@TK2MSFTN GP10.phx.gbl... Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and
Structure B.

Structure A
Public Fname as String
Public LastName as String
Public City as String
Public Zip as String
End Structure
Structrure B
Public Fname as String
Public LastName as String
Public City as String
Public Zip as String
End Structure

How can I compare these two data types.. ie Fname, LastName, City, Zip of
Structure A should match Fname, LastName, City, Zip of Sturcture
[shouldn't be ase sensitive.]

If Sturcture A = Structure Then

Do tthis ..
Else

End if
Thanks in advance.

Nov 21 '05 #4

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

Similar topics

6
2375
by: billy | last post by:
I've got a set of subclasses that each derive from a common base class. What I'd like to do is create a global array of the class types (or, class names) that a manager class can walk through in its constructor and instantiate one of each of the class types in this global array. So, it's almost like the global array has to hold data types as opposed to data. Basically, I currently have to add the items manually 1 at a time.
4
3194
by: troloo | last post by:
Hello, I hope you can help me :)) The story goes as follows: I have a class with different methods and member variables. I store pointers to objects of this class inside a vector. Now, I would like to have a variable 'window' which could contain pointers to different objects (like 'class t1', 'class t2', etc.). I tried to use templates to create variable 'T* window' but I had some troubles later storing pointer to such a template-enabled...
4
2275
by: No One | last post by:
Here is my problem: I have a certain set of well-defined manipulations that I have to apply to different types of data. In all cases the manipulations are exactly the same, and are to be performed on the different types of data. Currently I have a collection of functions that do exactly the same - the only difference between them is the type of data they act on. Let me present a toy example: I have the following two data types:
5
1764
by: Craig | last post by:
Hi everyone, As a relative new-comer to the wonderful world of .NET Framework and the C# langauge I have come across something that I would like to clarify (hopefully with the help of kind people such as yourselves). To quote, "Everything in C# is an object" (including "primitive" value types, primitive being in quotations because this is what my question concerns).
3
1608
by: person | last post by:
Hi, Is there an STL function/algorithm to compare two maps and return a map of the differences? I'm looking for a way to do an "exclusive or" between an old map and a new map and then work on the differences. Thanks, Frank
4
2462
by: Abdul Samad | last post by:
banfa just said that it is because so the compiler may not assign the same memory to two variables but my question is WHY DOES COPILER ASSIGNMS MEMORY WHEN THERE IS NO NEED OF IT? as the structure has no data types or member functions so why the memory needed to be assignem to structured variable with no data types? for what purpose? Regards
1
1350
by: WELCOME ### | last post by:
From Beginner : With Visual C++, there're 3 ways to create Windows Applications. One of these is by using Windows API (Application Program Interface). Also Windows Data Types are used to specify functions parameter types and return types in windows API. Windows Data Types are many as : HANDLE, HBRUSH, LPHANDLE ... etc Now all the types used by windows are contained in a header file "window.h ".So we must include this header file when we...
15
8456
by: Madhur | last post by:
Hi All, I would like you help me in creating an array of data types. I am interested in look at the the data type which looks like this Array a={int,float,char,int*..............................}, so that a should return me int and a should return me
1
3484
by: bantunks | last post by:
Hello, I am trying to figure out the advantages and disadvantages of exposing interfaces through Opaque data types in C. I have figured/found out the following two advantages 1. Higher level of abstraction 2. if the layout of the defined structure inside the source files changes, it will reduce/limit/minimize the amount of changes that may be needed in the code of the application that uses the library i.e. the library will itself handle...
0
9856
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9698
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10592
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...
1
10656
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10299
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...
1
7834
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5684
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
4495
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
3
3136
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.