console.write gives ascii values why?

Posted by Prakashrajmca under C# on 8/30/2011 | Points: 10 | Views : 1817 | Status : [Member] | Replies : 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

int web = Console.Read();
Console.WriteLine(web);
Console.Read();
}
}
}

the above code working as strange i could not understand..
if give input 12 it prints the output 49, why it gives wrong integer..(new to dotnet)..

Question:-

1) is console.Read() function only read a single character?
2) in the above program it displays ascII value of single character why?


Thanks in advance




Responses

Posted by: T.saravanan on: 8/30/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Console.Read() returns only character code.If using Console.ReadLine() means you get exact value but it returns the value as string.
For your reference....
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/c3f31b59-e523-43d9-9798-d3723d9b4296
http://msdn.microsoft.com/en-us/library/system.console.read.aspx#Y474

Thanks,
T.Saravanan

Prakashrajmca, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response