为什么我会得到参数1,不得与' ref&#x27传递。关键词?

发布于 2025-01-30 19:50:33 字数 618 浏览 1 评论 0原文

我试图通过引用从1到Form2传递字符串,要在Form2中修改字符串,并在Form1中使用更改的值。 这是我的代码:

内部form1.cs:

 private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
          
            string text = "aaa";
            Form frm2 = new Form2();
            frm2.ShowDialog(ref text); 
        }

内部form2.cs

public void ShowDialog(ref string von1)
        {
           
            textBox1.Text = von1;
            this.ShowDialog(); 
            von1 = textBox1.Text;
        }

我无法编译该项目,因为im遇到错误:

参数1可能不会与“ ref”关键字CS1615传递,

我在做什么错?

I am trying to pass an string by reference from From1 to Form2, want to modify the string in Form2 and use the altered value in Form1.
This is my code:

Inside Form1.cs:

 private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
          
            string text = "aaa";
            Form frm2 = new Form2();
            frm2.ShowDialog(ref text); 
        }

Inside Form2.cs

public void ShowDialog(ref string von1)
        {
           
            textBox1.Text = von1;
            this.ShowDialog(); 
            von1 = textBox1.Text;
        }

I'm not able to compile this project because im getting the error:

Argument 1 may not be passed with the 'ref' keyword CS1615

What am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文