Shazma Batool
Shazma Batool

Reputation: 13

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! */

Upvotes: 0

Views: 1237

Answers (1)

poseidon99
poseidon99

Reputation: 26

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

Upvotes: 1

Related Questions