|
-
Apr 11th, 2002, 01:53 AM
#1
Thread Starter
Hyperactive Member
What's the use of interfaces with structures?
Hey,
I was just playing with a structure (to solve my last binary IO problem) and I came up with a strange thing...
You can write a structure that implements an interface. I can then create an interface variable that I then set to the structure variable. In this way, I can access the interface methods (blah...blah...blah).
Anyway, what I noticed is every time I change a property in the structure I lose synchronization. I have to set the interface variable to the structure variable again. I'm assuming this is because dot net didn't create a reference but a copy for me...
This is OK, when I change the value of the struct, but when I change the struct through the interface, it doesn't take:
StructVar.TestVal = 50;
ITest = StructVar;
ITest.GetVal; <returns 50> // ok
but...
ITest.SetVal(25);
StructVar.TestVal; <returns 50> // not OK
any ideas how to make this work?
-scott
he he he
-
Apr 11th, 2002, 07:21 AM
#2
Frenzied Member
Structs are value types, you might want to try boxing.
Dont gain the world and lose your soul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|