Hi All, I need to create a 2-dimensional group of values, the first
dimension having 8 rows, while the 2nd is variable. I was thinking of
using List<T>, but MAYBE List<Tis not the way to go (I prefer
Type-safe but it is not truly necessary). So if not List<T>, what do
you recommend I use?
Thanks!
Rex 8 5109
Rex <Re**********@OneSimpleHabit.comwrote in
news:co********************************@4ax.com:
Hi All, I need to create a 2-dimensional group of values, the first
dimension having 8 rows, while the 2nd is variable. I was thinking of
using List<T>, but MAYBE List<Tis not the way to go (I prefer
Type-safe but it is not truly necessary). So if not List<T>, what do
you recommend I use?
Thanks!
Rex
How about :
List<int>[] myList = new List<int>[8];
Don't forget to initialize each value of the array:
for(int i=0; i<myList.Length; i++) myList[i] = new List<int>();
-mdb
Type-safe but it is not truly necessary). So if not List<T>, what do
you recommend I use?
A DataTable
On Jun 12, 11:15 am, Rex <RexForum4...@OneSimpleHabit.comwrote:
Hi All, I need to create a 2-dimensional group of values, the first
dimension having 8 rows, while the 2nd is variable. I was thinking of
using List<T>, but MAYBE List<Tis not the way to go (I prefer
Type-safe but it is not truly necessary). So if not List<T>, what do
you recommend I use?
Thanks!
Rex
I would use List<Twhere T is a user defined class that has two
properties.
"Rex" <Re**********@OneSimpleHabit.comschrieb im Newsbeitrag
news:co********************************@4ax.com...
Hi All, I need to create a 2-dimensional group of values, the first
dimension having 8 rows, while the 2nd is variable. I was thinking of
using List<T>, but MAYBE List<Tis not the way to go (I prefer
Type-safe but it is not truly necessary). So if not List<T>, what do
you recommend I use?
Thanks!
Rex
You can use:
T[][]
List<T>[]
List<T[]>
List<List>>
they or all type safe
List<can change in length (without creating a wole new list), while array
can't. Still different arraytype element of a list (List<or array) can
differ in length.
So I would recommend
T[][]
if the length of each roew doesn't change.
List<T>[]
if the length of each row can change over time
HTH
Christof.
Thank you, Guys, for the help. I'm now going to show you how I'm still
somewhat of a Newbie in C#: I have successfully used List<Tbut I'm
not yet clear at the detail level about your offered solutions. I
think that upon reflection I will MOSTLY get what you-all suggested.
But I think the KEY statement that would help me is so see an ADD
using any of these solutions. So can anyone give me, say, the
declaration and then a sample .Add statement ??? I sure would
appreciate it,
Rex
On Tue, 12 Jun 2007 11:15:23 -0400, Rex
<Re**********@OneSimpleHabit.comwrote:
>Hi All, I need to create a 2-dimensional group of values, the first dimension having 8 rows, while the 2nd is variable. I was thinking of using List<T>, but MAYBE List<Tis not the way to go (I prefer Type-safe but it is not truly necessary). So if not List<T>, what do you recommend I use? Thanks! Rex
"Rex" <Re**********@OneSimpleHabit.comwrote in message
news:i5********************************@4ax.com...
Thank you, Guys, for the help. I'm now going to show you how I'm still
somewhat of a Newbie in C#: I have successfully used List<Tbut I'm
not yet clear at the detail level about your offered solutions. I
think that upon reflection I will MOSTLY get what you-all suggested.
But I think the KEY statement that would help me is so see an ADD
using any of these solutions. So can anyone give me, say, the
declaration and then a sample .Add statement ??? I sure would
appreciate it,
Using Michael Bray's suggestion of an array of List<T>, which is the best
for your situation:
Following his code, to add an element to row i, do:
myList[i].Add(element);
Rex
On Tue, 12 Jun 2007 11:15:23 -0400, Rex
<Re**********@OneSimpleHabit.comwrote:
>>Hi All, I need to create a 2-dimensional group of values, the first dimension having 8 rows, while the 2nd is variable. I was thinking of using List<T>, but MAYBE List<Tis not the way to go (I prefer Type-safe but it is not truly necessary). So if not List<T>, what do you recommend I use? Thanks! Rex
I think I get it - very simple! I sure appreciate it, Ben and Michael
(and everyone else),
Rex
On Tue, 12 Jun 2007 13:04:13 -0500, "Ben Voigt [C++ MVP]"
<rb*@nospam.nospamwrote:
> "Rex" <Re**********@OneSimpleHabit.comwrote in message news:i5********************************@4ax.com.. .
>Thank you, Guys, for the help. I'm now going to show you how I'm still somewhat of a Newbie in C#: I have successfully used List<Tbut I'm not yet clear at the detail level about your offered solutions. I think that upon reflection I will MOSTLY get what you-all suggested. But I think the KEY statement that would help me is so see an ADD using any of these solutions. So can anyone give me, say, the declaration and then a sample .Add statement ??? I sure would appreciate it,
Using Michael Bray's suggestion of an array of List<T>, which is the best for your situation:
Following his code, to add an element to row i, do:
myList[i].Add(element);
>Rex
On Tue, 12 Jun 2007 11:15:23 -0400, Rex <Re**********@OneSimpleHabit.comwrote:
>>>Hi All, I need to create a 2-dimensional group of values, the first dimension having 8 rows, while the 2nd is variable. I was thinking of using List<T>, but MAYBE List<Tis not the way to go (I prefer Type-safe but it is not truly necessary). So if not List<T>, what do you recommend I use? Thanks! Rex
On Jun 12, 1:53 pm, Rex <RexForum4...@OneSimpleHabit.comwrote:
Thank you, Guys, for the help. I'm now going to show you how I'm still
somewhat of a Newbie in C#: I have successfully used List<Tbut I'm
not yet clear at the detail level about your offered solutions. I
think that upon reflection I will MOSTLY get what you-all suggested.
But I think the KEY statement that would help me is so see an ADD
using any of these solutions. So can anyone give me, say, the
declaration and then a sample .Add statement ??? I sure would
appreciate it,
Rex
On Tue, 12 Jun 2007 11:15:23 -0400, Rex
<RexForum4...@OneSimpleHabit.comwrote:
Hi All, I need to create a 2-dimensional group of values, the first
dimension having 8 rows, while the 2nd is variable. I was thinking of
using List<T>, but MAYBE List<Tis not the way to go (I prefer
Type-safe but it is not truly necessary). So if not List<T>, what do
you recommend I use?
Say you have a class with two properties. Class name is Class1, and
property names are A and B. You also have a varible defined as:
List<Class1myList = new List<Class1>();
To add a new value:
Class1 myClass = new Class1();
myClass.A = somevalue;
myClass.B = someothervalue;
myList.Add(myClass); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave |
last post by:
Hello all,
After perusing the Standard, I believe it is true to say that once you
insert an element into a std::list<>, its location in memory never changes.
This makes a std::list<> ideal for...
|
by: Mikhail N. Kupchik |
last post by:
Hi All.
I have a question regarding C++ programming language standard. It
is related to standard library, not to the core language.
Is it portable to instantiate template class std::list<>...
|
by: matty.hall |
last post by:
I have two classes: a base class (BaseClass) and a class deriving from
it (DerivedClass). I have a List<DerivedClass> that for various
reasons needs to be of that type, and not a List<BaseClass>....
|
by: Andrew Robinson |
last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v>
depending on input parameters and options to the method.
1. Is there any way to convert from a dictionary to a list...
|
by: Zytan |
last post by:
This returns the following error:
"Cannot modify the return value of
'System.Collections.Generic.List<MyStruct>.this' because it is
not a variable"
and I have no idea why! Do lists return copies...
|
by: Peted |
last post by:
I have the following code
public enum pdfFlags
{
PFD_DRAW_TO_WINDOW,
PFD_DRAW_TO_BITMAP,
PFD_SUPPORT_GDI,
PFD_SUPPORT_OPENGL,
PFD_GENERIC_ACCELERATED, PFD_GENERIC_FORMAT,
|
by: Lee Crabtree |
last post by:
This seems inconsistent and more than a little bizarre.
Array.Clear sets all elements of the array to their default values (0,
null, whatever), whereas List<>.Clear removes all items from the...
|
by: =?Utf-8?B?UGhpbA==?= |
last post by:
I have seen the samples for Find that explain how to use the predicate, but
they are always searching for a pre-defined value. What I don't understand
is how to search for a random value stored in...
|
by: paul.gibson |
last post by:
A simple code example is easier than trying to describe the issue. I
have:
public class myClassA
{
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |