tags:

views:

107

answers:

3

hi, I start dicoverig C# today ... as you know there is some difuculties

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
       int[] arr = new int[3];
            int i;
            for (i=0; i < 3; i++)
            {
                arr[i] = Console.Read();
            }
            for (int k = 0; k < 3; k++)
            {
                Console.Write(arr[k]);
            }     

            Console.ReadKey();
        }

    }
}

this code didn't work with me when i compiled it ...it make me put value for one time then he print other values ! any one here to help

+2  A: 

try this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      int[] arr = new int[3];
      int i;
      for (i = 0; i < 3; i++)
      {
        arr[i] = Convert.ToInt32(Console.ReadLine());
      }
      for (int k = 0; k < 3; k++)
      {
        Console.WriteLine(arr[k]);
      }

      Console.ReadKey();
    }

  }

}

Bye.

RRUZ
+1  A: 

Instead of

arr[i] = Console.Read();

try this:

arr[i] = (int)Console.ReadKey().KeyChar;

Console.Read() will continue to read the same character over and over as it will still be considered the next character from the input stream. The Console.ReadKey() function reads keys as they are pressed.

Andrew Hare
+1  A: 

If i understand you correcrtly this is what you want

int[] arr = new int[3];
            for (int i = 0; i < 3; i++)
                arr[i] = Convert.ToInt32(Console.ReadLine());
            for (int k = 0; k < 3; k++)
                Console.WriteLine(arr[k]);

            Console.ReadKey();
astander