為什么C#和VB.net都不支持基于返回值類型的重載
3 回答

皈依舞
TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個贊
Eric Lippert大大對于"為什么C#/.NET不……"一類的問題是這么回答的:
As I'm fond of pointing out, the answer to every question of the form "why doesn't product X have feature Y?" is the same. It's because in order for a product to have a feature, that feature must be: - thought of in the first place - desired - designed - specified - implemented - tested - documented - shipped to customers You've got to hit every single one of those things, otherwise, no feature.
“支持基于返回值類型的重載”是合理的(Java就可以,如果我沒記錯的話),但是C#不是Java,它“被設(shè)計(jì)成了這樣”。答案就是這樣。另外,如果你真的很需要返回值類型的重載,你可以選擇其他的途徑去解決,比如泛型或者out關(guān)鍵字一類的??倸w是有替代解決方案的。

犯罪嫌疑人X
TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個贊
如 int f();與 string f();
調(diào)用時(shí)候?qū)?f();請問是調(diào)用哪個呢?返回值我可以丟掉不用,哈哈~~
- 3 回答
- 0 關(guān)注
- 541 瀏覽
添加回答
舉報(bào)
0/150
提交
取消