Can anyone help.
I have the following in vb.net and need to convert it to c#. Seemed rather simple at first but I need to pass in the NamedObject variable as welll which is supported in vb.net but not in c#..
What are my options.
Here is the vb.net - notice the NamedObject
    Public Property Datos(ByVal NamedObject As String) As T
        Get
            Return CType(HttpContext.Current.Session.Item(NamedObject ), T)
        End Get
        Set(ByVal Value As T)
            HttpContext.Current.Session.Item(NamedObject ) = Value
        End Set
    End Property
and this is c# but it errors as it appears i can't pass in a parameter on a property
    public T Datos(string NamedObject)
    {
        get { return (T)HttpContext.Current.Session[NamedObject]; }
        set { HttpContext.Current.Session[NamedObject] = Value; }
    }
I would appreciate any input..
Thanks
You are looking for the indexer property. Basically implement a property called this. There's a nice tutorial here.
True, you are restricted to the one indexer, but you will be able to implement something like this:
public T this[string namedObject]
{
    get { return (T)HttpContext.Current.Session[namedObject]; }
    set { HttpContext.Current.Session[namedObject] = Value; }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With