【发布时间】:2020-09-07 23:28:06
【问题描述】:
我正在尝试做一个变量,当我调用它时,它会执行代码。
例如
string path1;
string path2;
bool check;
var make;// the variable in case
//other code
if(check == false)
{
make = File.Copy(path1, path2); // the thing impossible to do
}
else
{
make = File.Move(path1, path2);
}
make;//and here it should to run some code
这不会运行 make 中包含的代码。
但代码不得使用内部编译器,如 Roslyn,因为它太慢了。
我尝试过这样但不起作用:
Action make = File.Copy(path1, path2);
我不想将函数用作:
public void main()
{
make();
}
public void make()
{
if(check == false)
{
make = File.Copy(path1, path2);
}
else
{
make = File.Move(path1, path2);
}
}
可以这样做吗?谢谢
【问题讨论】:
标签: c# wpf function variables var