Venciity

[Jumpstart C#] Console Demos - Reading Characters

Jan 22nd, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.49 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class ReadingCharacters
  5. {
  6.     static void Main()
  7.     {
  8.         //if Unicode is not specified , it will read ASCII
  9.         //Works on .NET Framework 4.0 and above
  10.         //Console.InputEncoding = Encoding.Unicode;
  11.         //Console.OutputEncoding = Encoding.Unicode;
  12.  
  13.         Console.Write("Insert char: ");
  14.         int i = Console.Read();
  15.         char ch = (char)i;  // Cast the int value to char
  16.         Console.WriteLine("The code of '{0}' is {1}.", ch, i);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment