【发布时间】:2019-03-24 19:30:13
【问题描述】:
我想将字符串值从函数传递到内部函数。
private void datagrid_customer_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
for (int i = 0; i < datagrid_customer.Items.Count; i++)
{
if (Convert.ToString((datagrid_customer.SelectedCells[3].Column.GetCellContent(datagrid_customer.SelectedItem) as TextBlock).Text) == Convert.ToString((datagrid_customer.SelectedCells[1].Column.GetCellContent(datagrid_customer.Items[i]) as TextBlock).Text))
{
...
string a = (b + c + d).ToString();
}
}
我想将a 传递给另一个函数
datagrid_customer.SelectAll();
for (int i = 0; i < datagrid_customer.Items.Count; i++)
{
if (Convert.ToString((datagrid_customer.SelectedCells[43].Column.GetCellContent(datagrid_customer.Items[i]) as TextBlock).Text) == "0")
{
...
txt_f1.Text = a ;
}
}
我需要txt_f1.text = a,但我无权使用a。
我该怎么办?
【问题讨论】:
-
在
if声明的范围之外声明string a。您仍然可以在if语句中分配它,但如果您也在那里声明它,它就会超出范围。请参阅我上面链接的重复帖子。 -
string a将对datagrid_customer_SelectionChanged中的其余代码可见。在你的第一个循环之前声明string a;。
标签: c# wpf visual-studio function