我可以使用声明的变量或对象的实例从一种方法到另一种方法吗?
private void OnBrowseFileClick(object sender, RoutedEventArgs e)
{
string path = null;
path = OpenFile();
}
private string OpenFile()
{
string path = null;
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Title = "Open source file";
fileDialog.InitialDirectory = "c:\\";
fileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
fileDialog.FilterIndex = 2;
fileDialog.RestoreDirectory = true;
Nullable<bool> result = fileDialog.ShowDialog();
if (result == true)
{
path = fileDialog.FileName;
}
textBox1.Text = path;
return path;
}
现在,我想获得那条路径并将其写在excel上。我将如何做到这一点,请帮助,我在使用 C# 一周大。
private void btnCreateReport_Click(object sender, RoutedEventArgs e)
{
string filename = "sample.xls"; //Dummy Data
string functionName = "functionName"; //Dummy Data
string path = null;
AnalyzerCore.ViewModel.ReportGeneratorVM reportGeneratorVM = new AnalyzerCore.ViewModel.ReportGeneratorVM();
reportGeneratorVM.ReportGenerator(filename, functionName, path);
}
谢谢