473,938 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multidimensiona l Generics

I have a list:

List<RichTextBo xrtb;

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 multidimensiona l array
i.e.;

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


Sep 2 '06 #1
8 2898
Hi,

you can do it like this:

List<List<RichT extBox>rtb = new List<List<RichT extBox>>();

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

Regards,

Wiebe Tijsma

Chuck Bowling wrote:
I have a list:

List<RichTextBo xrtb;

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 multidimensiona l array
i.e.;

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

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

| List<List<RichT extBox>rtb = new List<List<RichT extBox>>();

.... 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<RichT extBox>rtb = new List<List<RichT extBox>>();
rtb.Add(new List<RichTextBo x>());
rtb[0].Add(new RichTextBox());
rtb[0][0].Text = "some text";

Wiebe

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

| List<List<RichT extBox>rtb = new List<List<RichT extBox>>();

... 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(IL ist<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*********@CA PITALStijsma.co mwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Yes, thanks for the addition, lets not forget adding the lists itself as
well :)

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

Wiebe

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

| List<List<RichT extBox>rtb = new List<List<RichT extBox>>();

... 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<RichT extBox>rtb = new List<List<RichT extBox>>();
rtb[0].Add(new List<RichTextBo x>());
rtb[0][0].Add(new RichTextBox());
rtb[0][0].Text = "some text";
"Wiebe Tijsma" <wi*********@CA PITALStijsma.co mwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Yes, thanks for the addition, lets not forget adding the lists itself as
well :)

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

Wiebe

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

| List<List<RichT extBox>rtb = new List<List<RichT extBox>>();

... not forgetting :

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

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

Joanna

Sep 3 '06 #7
"Chuck Bowling" <ch**********@s bcglobal-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<RichT extBox>rtb = new List<List<RichT extBox>>();
| rtb[0].Add(new List<RichTextBo x>());
| 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**********@s bcglobal-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<RichT extBox>rtb = new List<List<RichT extBox>>();
| rtb[0].Add(new List<RichTextBo x>());
| 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
1801
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 massive at the start? Any other ideas? Apparently Hashtable, ArrayList etc are useless as they all take one dimension. :( Please help me! Thanks, Naomi
3
8215
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 Add(Array XValues, Array YValues) How do I call the Add function, passing my array columns please. thanks
2
1388
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 And http://support.microsoft.com/kb/325696/EN-US/ But I can't find a solution for the problem???
23
2581
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 vs C++ templates. Does anyone knows a workaround to do this ? Thx : public class C<T> { private T myValue;
12
2762
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 it defines the language more completely. Great to use.
9
5997
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 Experience Only, Please. ...
2
3663
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 book. Upon onChange select event I would like to parse the data into a multidimensional Javascript array in order to check equipment availability for booking. But I can't figure out how to parse and upon JS HTML DOM reference I am not even sure...
13
3860
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 application that needs implementations in both Java and C#. I have the Java side done, and it works fantastic, and the C# side is nearly there. The problem I'm running into has to do with the differences in implementations of Generics between the two...
9
4522
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 function: x = new int;
0
10126
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9963
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11515
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11282
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9854
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6072
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3495
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.