Reputation: 401
I am in need of performing a volatile write on a variable that is an Enum type derived from Byte, but I am stucked.
This is my (example) code:
Public Class MyOwnClass
Friend Enum MyEnum As Byte
Val1
Val2
End Enum
Private MyEnumVar As MyEnum = MyEnum.Val1
Friend Sub SetMyEnumVar(ByVal value As MyEnum)
System.Threading.Volatile.Write(MyEnumVar, value) 'Error!
End Sub
End Class
Since Threading.Volatile.Write is not provided with a signature with those arguments I get this error
Error 1 Overload resolution failed because no accessible Write can be called without a narrowing conversion:
With the list of all the overloads of the method.
CTyping the first argument is not working, because CType
returns a casted value of course not with the same reference as MyEnumVar
where the method gets the first parameter abviously ByRef
instead.
CObject
that would return a reference is also not viable because the method also hasn't got the overload for an object type other than Write(Of T)(T, T)
where T
must be a class type.
So how can I accomplish my purpose?
Thanks.
Upvotes: 2
Views: 213
Reputation: 9991
You can use the Write(Of T) overload where T
is the type of Enum
.
System.Threading.Volatile.Write(Of [Enum])(MyEnumVar, value)
Upvotes: 1