Is there any way a user can input numbers into an array like you can in c++??? Or strings for that matter????

Recommended Answers

All 7 Replies

Yes.

Can you please show me how?? This is what I have so far:

public static void Main()
    {
        int[] myints = { 5, 10, 15 };
        bool[][] mybools = new bool[2][];
        mybools[0] = new bool[2];
        mybools[1] = new bool[1];
        double[,] mydoubles = new double[2, 2];
        string[] mystrings = new string[3];

        Console.WriteLine(" My first number: {0}, my second number {1}, my third number {2}", myints[0], myints[1], myints[2]);

        mybools[0][0] = true;
        mybools[0][1] = false;
        mybools[1][0] = true;

        Console.WriteLine(" ");
        Console.WriteLine(" This statement is {0}. The previous sentence is {1}. Both of these are {2}. So which sentence is right???", mybools[0][0], mybools[0][1], mybools[1][0]);
        Console.WriteLine(" ");

        mydoubles[0, 0] = 1234;
        mydoubles[0, 1] = 4444;
        mydoubles[1, 0] = 3.145678;
        mydoubles[1, 1] = 5.66789;

        Console.WriteLine(" This is a whole number: {0}, So is this: {1}", mydoubles[0, 0], mydoubles[0,1]);
        Console.WriteLine(" ");
        Console.WriteLine(" This is not a whole number: {0}, Neither is this: {1}", mydoubles[1, 0], mydoubles[1, 1]);
        Console.WriteLine(" ");


    }

I am learning from the C# station tutorial and I am confused a little. For instance, on the line that says bool[][], why do I need 2 complete brackets instead of one? And for the doubles, why does there need to be a comma like an xy location instead of having 2 complete brackets or one bracket like the int[] array?

I am also 20 years old btw. I am going to Rasmussen College and I am studying game and sim programming but they don't have c# so I am trying to learn it as well. Thank You again for your help. =)

mydoubles[0,1]=myInput

Seems like you should google Readline()

Thank You. And that works???? Can you show me??? like be redoing some of the code???

This is just me learning it. I have a 2 week break from school so i thought i'd try another language instead of c++ you know???

So you would like to learn multidimensional arrays?

Try to use for loops with them:

int[,] myInts = new int[2,3] { 1, 2, 3 }, { 4, 5, 6 } };
for(int i = 0; i < myInts.GetLenght(1); i++)
{
    for(int j = 0; j < myInts.GetLenght(0); j++)
    {
         Console.WriteLine("{0}", myInts[j, i]);
    }
}
Console.ReadLine();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.