Search code examples
c#console-applicationuser-inputconsole.readline

Why am getting red line under the Console.ReadLine() method in C# even when storing the user input in string type ?PS. red line removed using var?


Console.WriteLine("Enter arguments");
string input = Console.ReadLine();// red line under Console.ReadLine
Console.WriteLine("Arguments at run-time  " + input);

/* I want to show the user input in string through my Console.WriteLine method and I know by-default it is in string type so why am getting red line under Console.ReadLine when using string and not when store in var type? Thanks! */


Solution

  • The Console.ReadLine(); function can return a null value and the IDE indicates that for safety. Use string?.