473,471 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Declaring an array of List Generic Class elements

Hello,

I am declaring an element like this:
public static List<myListElementmyList = new List<myListElement>();

I would like to declare an array of this myList.
How would I modify the declaration of myList so it will represents an array?

Thanks
Eitan

Jun 25 '07 #1
5 1899

"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:55**********************************@microsof t.com...
Hello,

I am declaring an element like this:
public static List<myListElementmyList = new List<myListElement>();

I would like to declare an array of this myList.
How would I modify the declaration of myList so it will represents an
array?

Thanks
Eitan
public static List<myListElement>[] myList = new List<myListElement>[4];

Colin =^.^=
Jun 25 '07 #2
Hello Colin,
Thank you for your answer.

I tried the line below (before posting my question):
public static List<myListElement>[] myList = new
List<myListElement>[4]();
The difference is the brackets "()" after "[4]". The compiler generated an
error.

Can you explain to me why the error, and when would you need the brackets
"()"?

Thank you,
Eitan
"colin" wrote:
>
"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:55**********************************@microsof t.com...
Hello,

I am declaring an element like this:
public static List<myListElementmyList = new List<myListElement>();

I would like to declare an array of this myList.
How would I modify the declaration of myList so it will represents an
array?

Thanks
Eitan

public static List<myListElement>[] myList = new List<myListElement>[4];

Colin =^.^=
Jun 25 '07 #3
Eitan wrote:
Hello,

I am declaring an element like this:
public static List<myListElementmyList = new List<myListElement>();

I would like to declare an array of this myList.
How would I modify the declaration of myList so it will represents an
array?

Thanks
Eitan
Hi Eitan,

You can declare it like this:
public static List<myListElement>[] listArray = new List<myListElement>[10];

(To define an array of size 10)

But please note that each element in the array will still have to be
constructed. You could this in a for-loop:

///
for (int i = 0; i < listArray.Count; i++)
listArray[i] = new List<myListElement>();
///

--
Tom Spink
University of Edinburgh
Jun 25 '07 #4
Eitan wrote:
Hello Colin,
Thank you for your answer.

I tried the line below (before posting my question):
public static List<myListElement>[] myList = new
List<myListElement>[4]();
The difference is the brackets "()" after "[4]". The compiler generated
an error.

Can you explain to me why the error, and when would you need the brackets
"()"?

Thank you,
Eitan
"colin" wrote:
>>
"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:55**********************************@microso ft.com...
Hello,

I am declaring an element like this:
public static List<myListElementmyList = new List<myListElement>();

I would like to declare an array of this myList.
How would I modify the declaration of myList so it will represents an
array?

Thanks
Eitan

public static List<myListElement>[] myList = new List<myListElement>[4];

Colin =^.^=
Hi Eitan,

If you take a look at my response it may be a bit clearer what is going on.
When you're defining the array, you aren't constructing the List<objects,
just constructing an array of list objects. Parentheses are not required
for constructing an array, as the construction doesn't take parameters,
only a size of array to create given in the square brackets.

So, that being the case, you'll have to manually construct each List<>
object in your array.

--
Tom Spink
University of Edinburgh
Jun 25 '07 #5
Thank you!

"Tom Spink" wrote:
Eitan wrote:
Hello,

I am declaring an element like this:
public static List<myListElementmyList = new List<myListElement>();

I would like to declare an array of this myList.
How would I modify the declaration of myList so it will represents an
array?

Thanks
Eitan

Hi Eitan,

You can declare it like this:
public static List<myListElement>[] listArray = new List<myListElement>[10];

(To define an array of size 10)

But please note that each element in the array will still have to be
constructed. You could this in a for-loop:

///
for (int i = 0; i < listArray.Count; i++)
listArray[i] = new List<myListElement>();
///

--
Tom Spink
University of Edinburgh
Jun 25 '07 #6

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

Similar topics

5
by: Carlos Ribeiro | last post by:
Hello all, I'm posting this to the list with the intention to form a group of people interested in this type of solution. I'm not going to spam the list with it, unless for occasional and...
4
by: Peter | last post by:
I run into this situation all the time and I'm wondering what is the most efficient way to handle this issue: I'll be pulling data out of a data source and want to load the data into an array so...
19
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0...
18
by: Sam | last post by:
Hi All I'm planing to write an application which allows users dynamically add their points (say you can add upto 30,000) and then draw xy graph. Should I use an array for my coordinate point...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
35
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...
2
by: Fred Mellender | last post by:
I am trying to use reflection to output the fields (names and values) of an arbitrary object -- an object dump to a TreeView. It works pretty well, but I am having trouble with generic lists,...
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
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...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.