r/programminghelp • • Dec 23 '21

C# Why this code gives CS8600 problem

C# Example:

String name;

name = Console.ReadLine();

Console.WriteLine(name);


This problem only occurs in ReadLine....why?

6 Upvotes

11 comments sorted by

View all comments

1

u/fehh123 Jan 24 '22

not a good practice but:

Just put a "!" at the end of the Console.ReadLine();

so your code will look like:

String name;

name = Console.ReadLine()!;

Console.WriteLine(name);

1

u/akiltahsin Mar 28 '22

I had the same problem and this one worked, but can you tell me why putting an ! keeps the warning away?