none
Convert RRS feed

Answers

  • You can use Int32 Parse method, or TryParse. The first will throw exception if it is not a number that can be parsed to int.

    You can also take a look at the Convert class, it also has methods to convert between different types.

    • Proposed as answer by Heslacher Tuesday, July 31, 2012 7:02 PM
    • Marked as answer by Mike FengModerator Thursday, August 9, 2012 3:27 PM
    Tuesday, July 31, 2012 2:08 PM
    Moderator

All replies

  • You can use Int32 Parse method, or TryParse. The first will throw exception if it is not a number that can be parsed to int.

    You can also take a look at the Convert class, it also has methods to convert between different types.

    • Proposed as answer by Heslacher Tuesday, July 31, 2012 7:02 PM
    • Marked as answer by Mike FengModerator Thursday, August 9, 2012 3:27 PM
    Tuesday, July 31, 2012 2:08 PM
    Moderator
  • First read the character as Console.Read() function. This will return you the character. Then cast the character to int. You will get ascii value of that character. You can also use ReadKey method. I have shown both examples below.

    public static void Main(string[] args)
    {
        //First Method
        int character1 = Console.Read();
        Console.WriteLine(character1);    
    
        //Second Method
        int character2 = Console.ReadKey().KeyChar;
        Console.WriteLine(character2);
        Console.ReadLine();
    }

    I hope this helps.

    Please mark this post as answer if it solved your problem. Happy Programming!

    Tuesday, July 31, 2012 4:02 PM