C#'裁判'关键字,性能 [英] C# 'ref' keyword, performance

查看:144
本文介绍了C#'裁判'关键字,性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有需要传递给众多的方法(10)Bitmap对象,最后到它应当最终处置它的使用后的事件,那会是(性能明智),有利于它传递给通过引用而不是值每一个人的那些方法?

If you have a Bitmap object that needs to be passed to numerous methods (about 10), and finally to an event where it shall finally be disposed of after it's used, would it be (performance wise) beneficial to pass it to every one of those methods by reference instead of value?

按值传递,对象被复制,引用传递它不是。

Passing by value, the object is copied, passing by reference its not.

(性能是在这种情况下关键的。该应用程序需要尽可能快地运行。)

(Performance is critical in this situation. The application needs to run as fast as possible.)

推荐答案

位图是一个引用类型。按值传递一个引用类型不会复制对象,仅仅是参考的对象。将不会有任何性能优势通过引用而不是按值传递的位图。

Bitmap is a reference type. Passing a reference type by value does not copy the object, merely the reference to the object. There would be no performance benefit to passing the Bitmap by reference instead of by value.

这篇关于C#'裁判'关键字,性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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