如何在没有引用的情况下从调用方法传递DataGridView类对象作为参数 [英] How to pass DataGridView class object as argument from caller method without a reference

查看:138
本文介绍了如何在没有引用的情况下从调用方法传递DataGridView类对象作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将DataGridView类对象作为参数传递给没有引用的方法。当我在没有REF关键字的情况下执行它时,仍然对调用方法内部的参数进行任何更改,并在调用方法中更改DataGridView。

解决方案

您正在将DataGridview引用发送到方法,所以如果您修改为调用方法中的参数将反映在您的被调用方法中。如果您不想在调用方法中更改参数,则需要创建DataGridView的一个副本,并且需要将新副本作为参数发送。



传递价值C# - Stack Overflow [ ^ ]



但是这里最好发送你想要的数据而不是完整的DataGridView。



如果您想将DataGridview作为参数发送,您仍可以找到克隆DataGridView 此处。

Is it possible to pass DataGridView class object as argument to a method without a reference. When I do it without REF key word, still any change to argument inside called method results with change in DataGridView in caller method.

解决方案

You are sending DataGridview reference to the method so if you modified to argument in the caller method that will reflect in your called method. If you don't want to change the argument in caller method you need to create one copy of the DataGridView and you need to send new copy as argument.

Pass by Value in C# - Stack Overflow[^]

But here better to send what ever data you want instead of complete DataGridView.

Still if you want to send DataGridview as parameter you can finding cloning DataGridView here.


这篇关于如何在没有引用的情况下从调用方法传递DataGridView类对象作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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