Read-write property in VB.NET interface

I would like to write an interface class and use it as follows

public Interface IFunction
  property name as string
end interface

public class ModelFunction
   implements IFunction

  public property name as string

  public sub new()

end class

* EDIT (deleted the following sentence for being noob, thanks @damien_the_unbeliever for pointing this out): But this cannot be done because the property in the vb.net interface should be read-only or writeonly (as far as I can get it) *

Now I wrote this, but it seems a bit wrong:

public Interface IFunction
  Readlonly property getName() as string
  writeonly property writeName() as string
end interface

public class ModelFunction
 implements IFunction

 ....
end class

Does anyone have a better solution for this? or can help me with properties in an interface class. Read some articles here about stackoverflow, but none of them pointed me in the right direction.

+5
source share
1 answer

This works fine for me:

Public Class Class1
    Implements Thing

    Property Gary As Int32 Implements Thing.Gary
        Get
            Return 10
        End Get
        Set(value As Int32)

        End Set
    End Property
End Class

Public Interface Thing
    Property Gary As Int32
End Interface

There is even an example on the documentation page Interface:

Interface IAsset
    Event ComittedChange(ByVal Success As Boolean)
    Property Division() As String 
    Function GetID() As Integer 
End Interface
+7
source

All Articles