Are there properties that differ in parameters and return type?

后端 未结 2 1682
后悔当初
后悔当初 2021-01-25 20:02

I have a class call CalcArray that has an array of doubles called Amounts(), and two ints, StartPeriod and EndPeriod

2条回答
  •  难免孤独
    2021-01-25 20:18

    You can do this with a function returning a different based on how it is called. Especially since you have a param, a function might be more appropriate:

    Public Function AnAmount(Of T)(parm As SomeType) As T
    

    to use it:

    Dim n as Decimal
    n = AnAmount(Of Decimal)(foo)
    

    Its very useful as a way to avoid returning an object and then have to use CType to convert the return. In this case, an amount implies a value type, but the function would accept Point, Rectangle etc as T, so you might need to check valid type requests.

提交回复
热议问题