Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.