Re: Structures not behaving as value types

Matthew Wills <[email protected]> Mon, 25 Feb 2008 09:39:25 +1100
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <OFA185DEAD.CFC3F9C5-ONCA2573F9.007C66F3-CA2573F9.007C7805@nab.com.au>
Richard,

Show us the code for strFieldMask. I would bet you are using some reference
types in it.

Seeya
Matthew Wills | Solution Designer | Adviser Tools and Services | Financial
Planning and Third Party | NAB Technology

Phone: 02 9376 4029 | Mobile: 0435 002 520 | Email:
[email protected]




             Richard Kucia
             <[email protected]>
                                                                        To
                                       [email protected]
                                                                        cc

                                                                   Subject
                                       [DOTNET-CLR] Structures not
                                       behaving as value types










I have a VB.Net declaration of a structure strFieldMask. The intended
purpose is to store a bunch of bits, like a bit vector. The structure also
has operator declarations for =, <>, And, Or, Not and <<, plus some other
methods for bit manipulation.

The problem is that variables of type strFieldMask seem to behave as
though there was a singleton strFieldMask and all instances shared it.

Consider this:

Dim Mask1 as strFieldMask
Dim Mask2 as strFieldMask

Mask1 = (formula for computing the next unused mask value)
Debug.WriteLine(Mask1.ToString))
Mask2 = (same formula)
Debug.WriteLine(Mask1.ToString)) ' Yes, Mask1, not Mask2

The result from the first WriteLine might be "0x10" and the result from
the second WriteLine might be "0x20".

I've successfully used structures before, but this is the first time I've
tried overloading the operators. Has that caused the behavior I'm seeing?

Thanks.



National Australia Bank Ltd - ABN 12 004 044 937
This email may contain confidential information. If you are not the intended
recipient, please immediately notify us at [email protected] or by replying to
the sender, and then destroy all copies of this email. Except where this email
indicates otherwise, views expressed in this email are those of the sender and not
of National Australia Bank Ltd. Advice in this email does not take account of your
objectives, financial situation, or needs. It is important for you to consider these
matters and, if the e-mail refers to a product(s), you should read the relevant
Product Disclosure Statement(s)/other disclosure document(s) before making any
decisions. If you do not want email marketing from us in future, forward this email
with "unsubscribe" in the subject line to [email protected] in order to
stop marketing emails from this sender. National Australia Bank Ltd does not
represent that this email is free of errors, viruses or interference.

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com