Search code examples
c#variablesvariable-assignmentconsole.readline

Can you set a variable to console.ReadLIne()?


I am new to programming here. This is a question that i have been mulling over. Can you set a variable to Console.ReadLine() in c# and then call the variable instead of typing Console.ReadLine() everytime? For example:

//Set Variable
var read = Console.ReadLine();
//Call vaariable
read;

Solution

  • Like this:

    //Set Variable
    Func<string> read = Console.ReadLine;
    //Call vaariable
    read();