Reading an array from console - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Reading an array from console

simion314simion314 Posts: 39Member
I want to make a console application that reads a 2d array,
i tried to use Console.Read but it doesn't work.
Help me.
simion314

Comments

  • loopmaxloopmax Posts: 3Member
    : I want to make a console application that reads a 2d array,
    : i tried to use Console.Read but it doesn't work.
    : Help me.
    : simion314
    :

    Why don't you use a ArrayList, it is a 2d array. then foreach the arraylist.

    this is what you asked:

    using System;
    namespace ArraysSamp
    {
    class Class1
    {
    static void Main(string[] args)
    {
    string[,] names = new string[,]
    {
    {"Rosy","Amy"},
    {"Peter","Albert"}
    };
    foreach( string str in names)
    {
    Console.WriteLine(str);
    }
    }

    }}

  • simion314simion314 Posts: 39Member

    thx for help.
    I had solved this problem like this:
    public static void read(int n,double[,] M){

    for (int i = 0; i < n; i++)
    {
    for (int j = 0; j < n; j++)
    {
    Console.Write("m[{0}][{1}]=", i, j);
    string s =Console.ReadLine();

    M[i, j] = Convert.ToDouble(s);

    }
    ....

    but if you are still there tell me how to write a tab doesn't work
    simion314

  • loopmaxloopmax Posts: 3Member
    :
    : thx for help.
    : I had solved this problem like this:
    : public static void read(int n,double[,] M){
    :
    : for (int i = 0; i < n; i++)
    : {
    : for (int j = 0; j < n; j++)
    : {
    : Console.Write("m[{0}][{1}]=", i, j);
    : string s =Console.ReadLine();
    :
    : M[i, j] = Convert.ToDouble(s);
    :
    : }
    : ....
    :
    : but if you are still there tell me how to write a tab doesn't work
    : simion314
    :
    :
    looks OK, what r u trying to do? wht do u mean by tab
Sign In or Register to comment.