Reputation: 155
I have a string that I create as a get; set;:
public static string userDirInput { get; set; }
I use Console.Read();
to give it a value:
userDirInput = Convert.ToString(Console.Read());
and before I go to compare it I print it out :
Console.Write("read as " + (string)userDirInput);
Its printing out unicode values and not readable text...
what do I do to get it to print out readable text?
Upvotes: 1
Views: 165
Reputation: 564831
You probably want to use Console.ReadLine
, which returns a string
. Console.Read
only reads a single character, and returns it as an Int32
. If you were to cast it to char
, you'd see you are reading the first letter the user typed, not the entire string.
Upvotes: 5
Reputation: 27614
It's because Console.Read
returns an int
, so it's more suitable to get char
:
int i = Console.Read();
char ch = Convert.ToChar(i);
Use ReadLine
to get input as string:
string input = Console.ReadLine();
Upvotes: 2