您可以将变量设置为 console.ReadLIne() 吗?
Can you set a variable to console.ReadLIne()?
我是这里编程的新手。这是我一直在思考的问题。您可以在 c# 中将变量设置为 Console.ReadLine() 然后调用该变量而不是每次都键入 Console.ReadLine() 吗?例如:
//Set Variable
var read = Console.ReadLine();
//Call vaariable
read;
听起来你想创建一个委托,像这样:
var readOp = new Func<string>(() => Console.ReadLine());
然后你可以像这样使用它:
System.Diagnostics.Debug.Print(readOp());
或者这个,或者其他什么:
string myLine = readOp();
像这样:
//Set Variable
Func<string> read = Console.ReadLine;
//Call vaariable
read();
我是这里编程的新手。这是我一直在思考的问题。您可以在 c# 中将变量设置为 Console.ReadLine() 然后调用该变量而不是每次都键入 Console.ReadLine() 吗?例如:
//Set Variable
var read = Console.ReadLine();
//Call vaariable
read;
听起来你想创建一个委托,像这样:
var readOp = new Func<string>(() => Console.ReadLine());
然后你可以像这样使用它:
System.Diagnostics.Debug.Print(readOp());
或者这个,或者其他什么:
string myLine = readOp();
像这样:
//Set Variable
Func<string> read = Console.ReadLine;
//Call vaariable
read();