I’ve been using Visual Basic for quite a while and have recently made the decision to begin learning C# as a step forward into learning more complex languages.
As a part of this jump I have decided to convert a few of my old VB projects by hand into C#. The issue I am having is with converting a library that had a class using properties with arguments/indexes.
The property would be something like this in VB:
Friend Property Aproperty(ByVal Index As Integer) As AClass
Get
Return Alist.Item(Index)
End Get
Set(ByVal value As KeyClass)
Alist.Item(Index) = value
End Set
End Property
When I used the property it would be used like this:
Bclass.Aproperty(5) = new AClass
It is this sort of thing I want to achive in C# but cannot figure out for the life of me just how to do this as it seems C# can’t do this sort of thing.
Since C# doesn’t support parameterized properties (which is what you are showing), you need to convert this code to two functions, a GetAProperty(index) and a SetAProperty(index).
We converted a 50,000+ LOC application from VB to C# and it required extensive modifications like this due to the dependence on parameterized properties. However, it is doable, it just requires a different way of thinking about properties like this.