0

In C# Console, we use Console.ReadLine() to accept inputs, this method returns the input in System.String format by default.

My question, is there a way/any method to accept input from Console as it is, I mean, if I type Integer then I must get integer in my code without converting the input to String.

  • 3
    No, everything read from the console is a string. You have to perform the conversion. –  Mar 04 '19 at 16:33
  • 1
    https://stackoverflow.com/questions/24443827/reading-an-integer-from-user-input – Attersson Mar 04 '19 at 16:33
  • 1
    The reason why you cant just interpret the datatype is because if a user inputs `0x0F`, do you parse that as a byte or as a string? There is no context as to how the stream reader should read the data buffer. Both a string and a byte are valid types in this scenario, it just all depends on the use case for the data as to what type is appropriate for it. – Kieran Devlin Mar 04 '19 at 16:44
  • https://stackoverflow.com/a/4805314/17034 – Hans Passant Mar 04 '19 at 16:47

0 Answers0