是否存在参数和返回类型不同的属性? [英] Are there properties that differ in parameters and return type?

查看:32
本文介绍了是否存在参数和返回类型不同的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类调用 CalcArray,它有一个名为 Amounts() 的双精度数组和两个 intsStartPeriodEndPeriod.

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

用户几乎总是想与数组中的项目交互,而不是周期或对象本身.所以理想情况下,我想:

The user almost always wants to interact with the items in the array, not the Periods or the object itself. So ideally, I'd like:

property AnAmount() as CalcArray 'So the user can talk to the object if they need to
property AnAmount(i as Integer) as Double 'So the user can just get the value directly

这似乎有时有效,但有时无效.这只是一个语法问题吗?或者这样的过载是不可能的?

This seems to work sometimes and not others. Is this simply a syntax issue? or is such an overload not possible?

推荐答案

您可能会遇到一个限制,即函数或属性不能仅因返回类型而变化.一般来说,如果签名发生了变化,输出类型也会在过载时发生变化.还要注意使用默认属性的限制需要一个参数.在某些情况下,类继承是问题,被隐藏的属性和函数可能需要明确指定 Shadows、Overloads、Overrides 等,否则语言将禁止隐藏.

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.

这篇关于是否存在参数和返回类型不同的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆