Results 1 to 2 of 2

Thread: What's the use of interfaces with structures?

  1. #1

    Thread Starter
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327

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

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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
  •  



Click Here to Expand Forum to Full Width