List of List?

J

jodleren

Hi

I need a double array such as Data[x, y], can I do that by 2 list?
What would you suggest?

The still a bit newbie
Sonnich
 
J

Jeff Johnson

I need a double array such as Data[x, y], can I do that by 2 list?
What would you suggest?

I would suggest you tell us what you need the array for so that we can give
you a good recommendation on how to implement it. If this is, for example, a
grid and you will always have some meaningful value stored in each "cell"
then a two-dimensional (not "double") array would be good. If you might have
a ragged array then an array of arrays may be a beeter choice. A list of
lists would be good if you will have ragged rows which may change size
often.
 
J

jodleren

I need a double array such as Data[x, y], can I do that by 2 list?
What would you suggest?

I would suggest you tell us what you need the array for so that we can give
you a good recommendation on how to implement it. If this is, for example, a
grid and you will always have some meaningful value stored in each "cell"
then a two-dimensional (not "double") array would be good. If you might have
a ragged array then an array of arrays may be a beeter choice. A list of
lists would be good if you will have ragged rows which may change size
often.

Well, I need a public (property) for Data[x, y], of strings

S
 
J

jodleren

Well, I need a public (property) for Data[x, y], of strings

That doesn't really answer the question.

Note that you can have an indexer with two parameters. For example:

   class Class1
   {
     private string[,] _data;

     public string this[int x, int y]
     {
       get { return _data[x, y]; }
     }
   }

You could also just expose the underlying data structure directly from a
property, whatever it happens to be.  For example:

   class Class1
   {
     private string[,] _data;

     public string[,] Data
     {
       get { return _data; }
     }
   }

But the question still remains what the backing data structure would be,
which depends on what you're storing and why.

Pete

Hi

I want to store strings, so I can:

mycomponent.data[0,1] = "sdfsadf";

some_label.text = mycomponent.data[10,22];

WBR
Sonnich
 
A

Arne Vajhøj

Well, I need a public (property) for Data[x, y], of strings

That doesn't really answer the question.

Note that you can have an indexer with two parameters. For example:

class Class1
{
private string[,] _data;

public string this[int x, int y]
{
get { return _data[x, y]; }
}
}

You could also just expose the underlying data structure directly from a
property, whatever it happens to be. For example:

class Class1
{
private string[,] _data;

public string[,] Data
{
get { return _data; }
}
}

But the question still remains what the backing data structure would be,
which depends on what you're storing and why.

I want to store strings, so I can:

mycomponent.data[0,1] = "sdfsadf";

some_label.text = mycomponent.data[10,22];

mycomponent.Data[0,1] = "sdfsadf";
some_label.text = mycomponent.Data[10,22];

should work with Peters second example.

mycomponent[0,1] = "sdfsadf";
some_label.text = mycomponent[10,22];

should work with the first example.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top