locked
What the meaning of "this" in csharp and how to transfer to vb RRS feed

  • Question

  • User-189731446 posted

    I have this class in c sharp:

    public class Parameter

    {

    private NameValueCollection Parameters;public virtual string this[string ParameterName]

    {

    get

    {

    return this.Parameters[ParameterName];

    }

    set

    {

    this.Parameters[ParameterName] = value;

    }

    }

    }

    I confused about the this in here public virtual string this[string ParameterName]

    so i transfer it to VB like below (is it ok?)

    Public Class Parameter
    Private Parameters As NameValueCollection

    Public Overridable Property Parameter(ByVal ParameterName As String) As String

    Get

    Return Me.Parameters(ParameterName)

    End Get

    Set(ByVal value As String)
    Me.Parameters(ParameterName) = value

    End Set

    End Property

    End Class

    It is not showing any error, but is that correct ?

    Thanks in Advance

    Thursday, December 4, 2008 4:40 AM

Answers

  • User541108374 posted

    Hi,

    in this case the keyword "this" is used for the indexer. Here's an example on how to use them: http://msdn.microsoft.com/en-us/library/2549tw02.aspx.

    Grz, Kris.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 4, 2008 5:12 AM
  • User397347636 posted

    The VB equivalent (via Instant VB) is:

    Public Class Parameter
    	Private Parameters As NameValueCollection
    	Default Public Overridable Property Item(ByVal ParameterName As String) As String
    		Get
    			Return Me.Parameters(ParameterName)
    		End Get
    		Set(ByVal value As String)
    			Me.Parameters(ParameterName) = value
    		End Set
    	End Property
    End Class
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 4, 2008 9:56 AM

All replies

  • User541108374 posted

    Hi,

    in this case the keyword "this" is used for the indexer. Here's an example on how to use them: http://msdn.microsoft.com/en-us/library/2549tw02.aspx.

    Grz, Kris.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 4, 2008 5:12 AM
  • User397347636 posted

    The VB equivalent (via Instant VB) is:

    Public Class Parameter
    	Private Parameters As NameValueCollection
    	Default Public Overridable Property Item(ByVal ParameterName As String) As String
    		Get
    			Return Me.Parameters(ParameterName)
    		End Get
    		Set(ByVal value As String)
    			Me.Parameters(ParameterName) = value
    		End Set
    	End Property
    End Class
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 4, 2008 9:56 AM