gpt4 book ai didi

c# - ref 或 out 参数必须是可赋值变量

转载 作者:太空狗 更新时间:2023-10-30 00:51:50 25 4
gpt4 key购买 nike

我正在编写一个可以建立反向代理连接的应用程序,但我遇到了问题!错误在这里:new Form1.ProxyConfig()

当我尝试运行它时出现错误:“A ref or out argument must be an assignable variable

private void startToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.startToolStripMenuItem.Text == "Start")
{
var form2 = new Form2();

if (form2.ShowDialog() != DialogResult.OK)
return;

int num1 = Form1.ProxyListenerStart(ref new Form1.ProxyConfig()
{
pclient_port = form2.ClientPort,
pp_start = form2.LocalStartPort,
pp_end = form2.LocalEndPort
}, ref this._PN);

if (num1 != 0)
int num2 = (int) MessageBox.Show("Error " + num1.ToString());
else startToolStripMenuItem.Text = "Stop";
}
else
{
Form1.ProxyListenerStop();

startToolStripMenuItem.Text = "Start";
listView1.Items.Clear();
toolStripStatusLabel2.Text = "0";
}
}
private struct ProxyConfig
{
public int pclient_port;
public int pp_start;
public int pp_end;
}

最佳答案

您不能像在此处那样同时创建变量并将其作为引用传递。试试这个:

var config = new Form1.ProxyConfig()
{
pclient_port = form2.ClientPort,
pp_start = form2.LocalStartPort,
pp_end = form2.LocalEndPort
};

int num1 = Form1.ProxyListenerStart( ref config, ref this._PN );

原因是它真的没有任何意义,请考虑以下场景:

if( int.TryParse( "123", out new int() ) )
{
// there's no way for us to actually use the value TryParse stored
// into the out parameter, since it doesn't have a name
}

关于c# - ref 或 out 参数必须是可赋值变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24828842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com