473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Multidimensional Generics

I have a list:

List<RichTextBoxrtb;

That represents an NxM matrix of rtb's. Is there some way to initialize a
generic that will allow me to access the List like a multidimensional array
i.e.;

rtb[2, 3].Text = "some text";


Sep 2 '06 #1
8 2871
Hi,

you can do it like this:

List<List<RichTextBox>rtb = new List<List<RichTextBox>>();

rtb[2][3].Text = "some text";

Regards,

Wiebe Tijsma

Chuck Bowling wrote:
I have a list:

List<RichTextBoxrtb;

That represents an NxM matrix of rtb's. Is there some way to initialize a
generic that will allow me to access the List like a multidimensional array
i.e.;

rtb[2, 3].Text = "some text";

Sep 2 '06 #2
"Wiebe Tijsma" <wi*********@CAPITALStijsma.coma écrit dans le message de
news: OC**************@TK2MSFTNGP04.phx.gbl...

| List<List<RichTextBox>rtb = new List<List<RichTextBox>>();

.... not forgetting :

rtb[2][3] = new RichTextBox(); or similar :-)

| rtb[2][3].Text = "some text";

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Sep 2 '06 #3
Yes, thanks for the addition, lets not forget adding the lists itself as
well :)

List<List<RichTextBox>rtb = new List<List<RichTextBox>>();
rtb.Add(new List<RichTextBox>());
rtb[0].Add(new RichTextBox());
rtb[0][0].Text = "some text";

Wiebe

Joanna Carter [TeamB] wrote:
"Wiebe Tijsma" <wi*********@CAPITALStijsma.coma écrit dans le message de
news: OC**************@TK2MSFTNGP04.phx.gbl...

| List<List<RichTextBox>rtb = new List<List<RichTextBox>>();

... not forgetting :

rtb[2][3] = new RichTextBox(); or similar :-)

| rtb[2][3].Text = "some text";

Joanna
Sep 2 '06 #4
Q: why not just use a multi-dimensional array of rtbs? However, the
following would wrap it reasonably well, assuming they exist first. At
least, it doesn't appear "jagged".

Marc

public class ArrayWrapper<T{
private readonly IList<Tdata;
private readonly int width;
public ArrayWrapper(IList<Tdata, int width) {
this.data = data;
this.width = width;
}
public T this[int x, int y] {
get { return data[GetIndex(x, y)]; }
set { data[GetIndex(x,y)] = value; }
}
private int GetIndex(int x, int y) {
return (y * width) + x;
}
}

Sep 2 '06 #5
Great! Thanks Wiebe, Joanna and Marc. :)
"Wiebe Tijsma" <wi*********@CAPITALStijsma.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Yes, thanks for the addition, lets not forget adding the lists itself as
well :)

List<List<RichTextBox>rtb = new List<List<RichTextBox>>();
rtb.Add(new List<RichTextBox>());
rtb[0].Add(new RichTextBox());
rtb[0][0].Text = "some text";

Wiebe

Joanna Carter [TeamB] wrote:
>"Wiebe Tijsma" <wi*********@CAPITALStijsma.coma écrit dans le message
de news: OC**************@TK2MSFTNGP04.phx.gbl...

| List<List<RichTextBox>rtb = new List<List<RichTextBox>>();

... not forgetting :

rtb[2][3] = new RichTextBox(); or similar :-)

| rtb[2][3].Text = "some text";

Joanna

Sep 3 '06 #6
Wiebe I'm a little confused on this. Should the code look more like this:

List<List<RichTextBox>rtb = new List<List<RichTextBox>>();
rtb[0].Add(new List<RichTextBox>());
rtb[0][0].Add(new RichTextBox());
rtb[0][0].Text = "some text";
"Wiebe Tijsma" <wi*********@CAPITALStijsma.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Yes, thanks for the addition, lets not forget adding the lists itself as
well :)

List<List<RichTextBox>rtb = new List<List<RichTextBox>>();
rtb.Add(new List<RichTextBox>());
rtb[0].Add(new RichTextBox());
rtb[0][0].Text = "some text";

Wiebe

Joanna Carter [TeamB] wrote:
>"Wiebe Tijsma" <wi*********@CAPITALStijsma.coma écrit dans le message
de news: OC**************@TK2MSFTNGP04.phx.gbl...

| List<List<RichTextBox>rtb = new List<List<RichTextBox>>();

... not forgetting :

rtb[2][3] = new RichTextBox(); or similar :-)

| rtb[2][3].Text = "some text";

Joanna

Sep 3 '06 #7
"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.neta écrit dans le message
de news: e3**************@TK2MSFTNGP04.phx.gbl...

| Wiebe I'm a little confused on this. Should the code look more like this:
|
| List<List<RichTextBox>rtb = new List<List<RichTextBox>>();
| rtb[0].Add(new List<RichTextBox>());
| rtb[0][0].Add(new RichTextBox());
| rtb[0][0].Text = "some text";

Chuck, thanks for filling in the holes, this is perfectly correct, but was
assumed by some of us :-)

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Sep 3 '06 #8
whoops... seems u worked it out perfectly

Joanna Carter [TeamB] wrote:
"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.neta écrit dans le message
de news: e3**************@TK2MSFTNGP04.phx.gbl...

| Wiebe I'm a little confused on this. Should the code look more like this:
|
| List<List<RichTextBox>rtb = new List<List<RichTextBox>>();
| rtb[0].Add(new List<RichTextBox>());
| rtb[0][0].Add(new RichTextBox());
| rtb[0][0].Text = "some text";

Chuck, thanks for filling in the holes, this is perfectly correct, but was
assumed by some of us :-)

Joanna
Sep 3 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Naomi | last post by:
Hi there, Just wondering, if there is any way to have a dynamic / unspecified size of an array? It obviously needs to be updated, deleted etc. The only way I thought is by making the array...
3
by: Claire | last post by:
I have a multidimensional array defined as private double myArray = new double; The first column of the array contains X values, the other contains Y values I have a charting function defined as...
2
by: Henrik | last post by:
im reciving an error when i tries to read multidimensional XML data, into my system. I'm receving the same errors discriped at: http://support.microsoft.com/default.aspx?scid=kb;en-us;325695...
23
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics...
12
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as...
9
by: sloan | last post by:
I'm not the sharpest knife in the drawer, but not a dummy either. I'm looking for a good book which goes over Generics in great detail. and to have as a reference book on my shelf. Personal...
2
by: BB | last post by:
Hello, I have a HTML form containing multidimensional selects listing equipments and their quantitites. This allow the users to select the kind of equipment and quantitites they would like to...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.