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

  • Are you sure it is a _red_ line? There is a _Warning_ in your Error List window. – H H May 03 '22 at 18:38
  • It is safe to ignore for now, or use `string? input` – H H May 03 '22 at 18:38
  • Yeah thanks red line removed using string? or var But am not getting the reason behind the error.. This is the warning in my error-list window of Visual Studio: "CS8600- Converting null literal or possible null value to non-nullable type." – Shazma Batool May 04 '22 at 07:25
  • That's still not an error, and that line isn't red. Read up about "nullable reference types". But as a beginner you may postpone that for a bit. – H H May 04 '22 at 07:31

1 Answers1

1

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

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
poseidon99
  • 26
  • 3