在下面的代码片段中,我创建了一个Guid,我也想在其他方法中使用它:
public string MyActionName()
{
Guid messageId = System.Guid.NewGuid();
string guid = messageId.ToString();
return guid;
}
我试过了
protected void Page_Load(object sender, EventArgs e)
{
Label2.Text = guid;
}
但我仍然无法使它正常工作
您需要像这样调用方法:
protected void Page_Load(object sender, EventArgs e)
{
Label2.Text = MyActionName();
}
您不能guid
直接从外部引用局部变量,因为它仅在方法本身内部可见。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句