Property

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    Property

    Hello,

    I am trying to convert some of my old VB.NET code to C# using an
    online tool but I am getting an error:

    Default Public Overloads Property Item(ByVal index As Integer)
    As Element
    Get
    Return TryCast(MyBase. BaseGet(index), Element)
    End Get
    Set(ByVal value As Element)
    If MyBase.BaseGet( index) IsNot Nothing Then
    MyBase.BaseRemo veAt(index)
    End If
    Me.BaseAdd(inde x, value)
    End Set
    End Property ' Item

    Becomes:

    public ConfigElement Item {
    get { return base.BaseGet(in dex) as ConfigElement; }
    set {
    if (base.BaseGet(i ndex) != null) {
    base.BaseRemove At(index);
    }
    this.BaseAdd(in dex, value);
    }
    }

    index disappears as input. Can't I use it?

    Thanks,
    Miguel
  • Peter Duniho

    #2
    Re: Property

    On Thu, 02 Oct 2008 10:01:32 -0700, shapper <mdmoura@gmail. comwrote:
    I am trying to convert some of my old VB.NET code to C# using an
    online tool but I am getting an error:
    >
    Default Public Overloads Property Item(ByVal index As Integer)
    As Element
    [...]
    >
    public ConfigElement Item {
    [...]
    >
    index disappears as input. Can't I use it?
    See http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx

    Comment

    • shapper

      #3
      Re: Property

      On Oct 2, 6:32 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
      wrote:
      On Thu, 02 Oct 2008 10:01:32 -0700, shapper <mdmo...@gmail. comwrote:
      I am trying to convert some of my old VB.NET code to C# using an
      online tool but I am getting an error:
      >
            Default Public Overloads Property Item(ByVal index As Integer)
      As Element
      [...]
      >
          public ConfigElement Item {
      [...]
      >
      index disappears as input. Can't I use it?
      >
      Seehttp://msdn.microsoft. com/en-us/library/6x16t2tx.aspx
      This is a class I created a long time ago but that inherits an ASP.NET
      existing class ...

      I can't just change this the way I want, right? I am a little bit
      lost.

      What I have is:

      Public Class ElementCollecti on
      Inherits ConfigurationEl ementCollection

      Default Public Overloads Property Item(ByVal index As Integer)
      As Element
      Get
      Return TryCast(MyBase. BaseGet(index), Element)
      End Get
      Set(ByVal value As Element)
      If MyBase.BaseGet( index) IsNot Nothing Then
      MyBase.BaseRemo veAt(index)
      End If
      Me.BaseAdd(inde x, value)
      End Set
      End Property

      Protected Overloads Overrides Function CreateNewElemen t() As
      ConfigurationEl ement
      Return New Element()
      End Function

      Protected Overloads Overrides Function GetElementKey(B yVal
      element As ConfigurationEl ement) As Object
      Return DirectCast(elem ent, Element).Name
      End Function

      End Class

      It is a "Overloadin g" property ... I am lost.

      Any idea?

      Thanks,
      Miguel

      Comment

      • Peter Duniho

        #4
        Re: Property

        On Thu, 02 Oct 2008 14:02:18 -0700, shapper <mdmoura@gmail. comwrote:
        >
        This is a class I created a long time ago but that inherits an ASP.NET
        existing class ...
        >
        I can't just change this the way I want, right? I am a little bit
        lost.
        >
        What I have is:
        >
        Public Class ElementCollecti on
        Inherits ConfigurationEl ementCollection
        >
        Default Public Overloads Property Item(ByVal index As Integer)
        As Element
        [...]
        End Property
        >
        [...]
        >
        End Class
        >
        It is a "Overloadin g" property ... I am lost.
        Well, a) C# supports overloaded indexers as well, and b) the code you
        posted only has the one overload anyway, so the "Overload" keyword appears
        to be superfluous.

        Did you read the page for which I provided a URL? It explains what a C#
        indexer looks like, which should give you enough information to
        reimplement the VB.NET indexer yourself.

        Pete

        Comment

        Working...