Are there properties that differ in parameters and return type?

后端 未结 2 1583
后悔当初
后悔当初 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:13

    You may be bumping into the limitation that a function or property cannot vary by only the return type. In general if the signature has changed, the output type can change also on an overload. Look out also for the limitation for using default properties requires an argument. In some cases class inheritance is the issue, properties and functions being shadowed may explicitly be required to nominate Shadows, Overloads, Overrides etc. or the shadowing will be disallowed by the language.

    If these don't cover the cases you've seen, try to catch an example of the problem and study all locations of the same named property in your solution, reporting the results here.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题