为什么“出”在.NET中的参数是一个坏主意? [英] Why are 'out' parameters in .NET a bad idea?

查看:125
本文介绍了为什么“出”在.NET中的参数是一个坏主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么出在.NET中的参数是一个坏主意?

Why are 'out' parameters in .NET a bad idea?

我最近问这个,但我从来没有真正的答案,除了它只是不必要的应用程序复杂化。有什么其他的原因有哪些?

I was recently asked this, but I had no real answer besides it's simply unnecessarily complicating an application. What other reasons are there?

推荐答案

嗯,他们是不是一个坏主意,我认为。 词典< K,V> 有一个 TryGetValue 方法,这是一个很好的例子,为什么出来的参数,有时一个很不错的事有。

Well, they aren't a bad idea I think. Dictionary<K, V> has a TryGetValue method which is a very good example why out parameters are sometimes a very nice thing to have.

您不应过度使用,当然这个功能,但它不是每个定义一个坏主意。尤其是没有在C#中,你必须记下函数声明的退出关键字的的通话,这使得它很明显这是怎么回事。

You should not overuse this feature of course, but it's not a bad idea per definition. Especially not in C# where you have to write down the out keyword in function declaration and call which makes it obvious what's going on.

这篇关于为什么“出”在.NET中的参数是一个坏主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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