Re: Structures not behaving as value types

Peter Obiefuna <[email protected]> Fri, 22 Feb 2008 15:21:11 -0700
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <[email protected]>
Ouch, my bad! I should have read the comments.

Well, it looks like whatever internal state that ToString() returns is a
static (shared) state of  strFieldMask. Could you post the strFieldMask type
if you may?
P

--------------------------------------------------
From: "Peter Obiefuna" <[email protected]>
Sent: Friday, February 22, 2008 1:15 PM
To: <[email protected]>
Subject: Re: [DOTNET-CLR] Structures not behaving as value types

>> 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
>

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

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