Re: Structures not behaving as value types
Peter Obiefuna <[email protected]> Fri, 22 Feb 2008 13:15:52 -0700
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <[email protected]> |
> Mask1 = (formula for computing the next unused mask value) > Debug.WriteLine(Mask1.ToString)) > Mask2 = (same formula) > Debug.WriteLine(Mask1.ToString)) ' Yes, Mask1, not Mask2 > It might be a simple typo. Your Writelines both call Mask1 instead of Mask1 and Mask2. P -------------------------------------------------- From: "Richard Kucia" <[email protected]> Sent: Friday, February 22, 2008 12:54 PM To: <[email protected]> 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. > > =================================== > This list is hosted by DevelopMentor® http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com