通过参考Textbox.Text传递 [英] Pass by Ref Textbox.Text

查看:186
本文介绍了通过参考Textbox.Text传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有,我想裁判传递textbox.text东西。我并不想通过整个文本框和我想的功能改变与返回的其他变量一起的文本。

I currently have something that I want to pass a textbox.text by ref. I don't want to pass the whole textbox and I want the function to change the text along with returning the other variable.

    public int function(int a, int b, string text)
    {
        //do something

        if (a + b > 50)
        {
            text = "Omg its bigger than 50!";
        }

        return (a + b);
    }



有没有办法通过裁判通过Textbox.text和内改变功能?

Is there a way to pass the Textbox.text by ref and change it inside the function?

推荐答案

您无法通过裁判传递一个属性,只有一个字段或变量。

You can't pass a property by ref, only a field or a variable.

MSDN :

属性不是变量。它们实际上是方法,因而不能为ref参数传递

Properties are not variables. They are actually methods, and therefore cannot be passed as ref parameters.

您必须使用中间变量:

string tmp = textBox.Text;
int x = function(1, 2, ref tmp);
textBox.Text = tmp;

这篇关于通过参考Textbox.Text传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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