Click here to Skip to main content
15,884,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I'm writting a method to create a multidimmensionnal array of different type (so i'm using an object array).
I wan't to fill a row of my array each time i'm calling the method but I don't know how to that.

I think it's very simple but i don't have enough knowledge in C#.

Could you help me please ?

(I'm a beginner in C#)

What I have tried:

So i tried something that i know it will not work, but "why not" :

C#
object[,,,,,] mileArray = new object[20, 20, 20, 20, 20, 20];

public void AddMile(int dist, int alt, string name, Font font, Brush brush, int i)
{
    mileArray[i,,,,,] = mileArray[dist, alt, name, font, brush];
}
Posted
Updated 7-May-20 1:35am
v2
Comments
phil.o 7-May-20 5:00am    
It is unclear what you want to store in your six-dimensions array. What is the requirement behind it, because I have the feeling that you are not using the right tool here.
Mineodo68 7-May-20 5:09am    
Hello,
In this six dimensions (or 5 if i don't use i) array, i want to store all caracteristics about a form and a text that i will draw later.
So it means a x position (here dist), y position (here alt), a name, a font type, a color (brush).
I added "i" to try to fill a row with it, but it's maybe unecessary.
I want to use an array because i will "parse" this array on another method.

I hope it's clear, i'm not english so i don't have all the grammatical expressions
Richard MacCutchan 7-May-20 5:16am    
That is really not the correct way to do things. You should create a class that contains the different properties and use that to hold all the information.
Mineodo68 7-May-20 5:19am    
But how can i do that if i want to have a look very clear on my values ?
Because here i tried to fill this array with value and caracteristics and after that, to write a method that draw something with each row of my array
phil.o 7-May-20 5:33am    
You create a class holding all values you need. Then you create a single-dimension array of this class.
public class Whatever
{
   // Properties
}

Whatever[] theArray = new Whatever[ARRAYSIZE];
// or (easier)
var list = new List<Whatever>();

1 solution

This solution summarises what we have told the OP in the comments and also gives some reference material.

The OP wants to store various attributes of a form to be referenced later in their program.

The correct way to go about this is to create a class representing the information they want to store about forms

(Hint - you could use the existing Form Class[^], or create a new class that inherits[^] from it)

If you have more than one instance of a form that you want to record or store or interrogate then you can add each Object to a collection - an array or (probably better) a List.

To get the information out of the object you refer to each objects Properties[^]

Give this a go, but do come back with another question if you get stuck
 
Share this answer
 
Comments
phil.o 7-May-20 7:38am    
Thanks for summarizing this thread :)
Mineodo68 28-May-20 4:03am    
Hello,
Sorry for the late answer.
Thank you very much ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900