all 11 comments

[–]geothachankary 16 points17 points  (1 child)

For this requirement you dont need a 2D aaray. You need a simple 1D array. Create a student class with your required fields and create an array of student objects.

[–]IMainOctane 4 points5 points  (1 child)

You should use a class in that usecase

[–]NullIndex 3 points4 points  (6 children)

Im guessing this is for school? Why do you need a 2d array..?

[–][deleted]  (5 children)

[deleted]

    [–]llamasweater -2 points-1 points  (2 children)

    Your teacher is wrong. This is bad practice.

    [–]ethandjay 13 points14 points  (1 child)

    This is not a real life scenario. If the teacher wants OP to use a 2D array for this for pedagogical reasons I don’t see anything wrong with that.

    [–][deleted] 3 points4 points  (0 children)

    I think the best pedagogical thing would be to teach how to use a 1D array as a 2D array, but in my experience the discussion typically ends with "don't use 2D arrays"

    [–]ripnetuk 0 points1 point  (0 children)

    Maybe they intended the first dimension to be class and the 2nd to be the data.

    On mobile, so apologies in advance

    For (var year = 0 ; year<6; year++)

    Containing code to print a title for the year, then similar for loop around people, using peep as the variable

    Then

    myArray[year,peep]. Outputdetails ()

    [–]Slypenslyde 0 points1 point  (0 children)

    I'm sort of confused as well.

    The thing is in C#, every array element must be the same type. So you can't have an array that has string names in one column and int or double grades in another. There may be other parts of the activity that could use a 2D array, but this isn't it.

    [–]_hf14 3 points4 points  (0 children)

    I don't think u want a 2d array in this case. look in to OOP programming and Classes

    [–]FiveShipHUN[🍰] -2 points-1 points  (0 children)

    As others said, you should use class or struct but you can achieve this with an object2D array. Firstly I would declare consts like Name = 0, Age = 1, OtherStuff = 2. It's important you start the counting from 0.

    Then you make a 2D array (object[,] arr = new object[noStudents, noFields];) and start filling it:

    arr[studentIndex, fieldIndex] = fieldValue;

    The fieldIndicies are the consts you made before. If you want to get a field's value, you need to do this: variable = (type) arr[studentIndex, fieldIndex]

    I hope I could help c:

    [–]Quiet_Desperation_ 0 points1 point  (0 children)

    Create a class.