Hi, i'm new to c# and need help on designing a programme. I need to create a 2d array which has to accept 12 values (3 verticalx4 horizontal)(with decimal places) . I have to be able to input the values of each element in the area using the console. I am having trouble doing this and any help would be appreciated

I want to able to input the values (doubles eg. "300.5") by using double.Parse(Console.ReadLine());

Wouldn't that code just be setting the values without any user input

You can do it like this also:

string[][] array = new string[3][];
array[0] = new string[4];
array[0][0]; = "a";
array[0][1] = "b"

Try this

double[,] myArray = new double[3,4];

for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
        Console.Write("Input value for position [{0}, {1}] : ", i, j);
        myArray[i,j] = double.Parse(Console.ReadLine());
    }
}

There is no error checking in there, so if the user puts something other than a number, it will fail.

simple input validation:

    bool temp = false;
    while (temp == false)
    {
        Console.Write("Input value for position [{0}, {1}] : ", i, j);
        temp=double.TryParse(Console.ReadLine(),out myArray[i, j]);
    }
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.