Thread: Input Problems and C# (CSharp) Tutorials

  1. #1
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96

    Lightbulb Input Problems and C# (CSharp) Tutorials

    Hi, there. I seen to have problems when I am trying to read the input from the keyboard.

    What happens if that I am trying to define an array to a char and I had declared a variabble called "YourName". I ttried to use [] but didn't work for char, and I tried to add the number to the array (for example: [16] but didn't work.

    I'd tried one of three things

    char YourName[16]; // but this didn't work
    char[] YourName[16]; // this didn't work either.
    char YourName = new char[16]; // this didn't work either.

    Yet...the error also told me that it can't convert char[] into char.

    YourName = Char.Parse(Console.ReadLine());

    However, I don't seem to have problems with:
    Console.Write(("Hello ", YourName.ToString());

    --------------------------------------------------------------

    So, here's the code to explain a little bit better.

    Code:
    Using System;
     
    class MainClass
    {
        public static void Main(string[] args)
        {
            char YourName[16];
            Console.Write(What is your name? (Up to 16 characters) ");
            YourName = Char.Parse(Console.ReadLine());
            Console.Write("Hello ", YourName.ToString());
        }
    }
    -------------------------------------------------------------------
    And, I am looking for a better tutorial that can show me examples along with the explaination. I had read the tutorial in Learn-C-Sharp.com but didn't help. The author should supposed to explain a little bit better about how I can use char with arrays and how can I be able to input into the screen, which means, by reading input from the keyboard, then to input it into a screen. It's true, however, char can hold only 1 character, which is 2 bytes. So, any good tutorials out there?

  2. #2
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    1. why don't you read it into a string instead?

    2. With C, C++ and C# use a loop to inter values. If you are using characters.

    3. What about C Sharp station other tutorials are found on this C programming site.

    Just some quick thoughts..
    Mr. C: Author and Instructor

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    In C# you no longer need those char arrays that were common in C.

    PHP Code:
    using System;
     
    class 
    MainClass
    {
        public static 
    void Main(string[] args)
        {
            
    string yourName;
            
    Console.Write"What is your name ?" );
            
    yourName Console.ReadLine();
            
    Console.Write("Hello {0}"yourName );
        }

    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96
    Okay. Thanks!

  5. #5
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Originally posted by Grayson_Peddie
    Okay. Thanks!
    It's nice isn't it?

Popular pages Recent additions subscribe to a feed