Re: Structures not behaving as value types
Jon Skeet <[email protected]> Fri, 22 Feb 2008 20:52:51 +0000
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <[email protected]> |
Richard Kucia wrote: > 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? It's hard to say without seeing the code - could you post a short but complete example? Jon =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com