473,809 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ 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<myListElem entmyList = new List<myListElem ent>();

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 1921

"Eitan" <Ei***@discussi ons.microsoft.c omwrote in message
news:55******** *************** ***********@mic rosoft.com...
Hello,

I am declaring an element like this:
public static List<myListElem entmyList = new List<myListElem ent>();

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<myListElem ent>[] myList = new List<myListElem ent>[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<myListElem ent>[] myList = new
List<myListElem ent>[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***@discussi ons.microsoft.c omwrote in message
news:55******** *************** ***********@mic rosoft.com...
Hello,

I am declaring an element like this:
public static List<myListElem entmyList = new List<myListElem ent>();

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<myListElem ent>[] myList = new List<myListElem ent>[4];

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

I am declaring an element like this:
public static List<myListElem entmyList = new List<myListElem ent>();

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<myListElem ent>[] listArray = new List<myListElem ent>[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<myListElem ent>();
///

--
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<myListElem ent>[] myList = new
List<myListElem ent>[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***@discussi ons.microsoft.c omwrote in message
news:55******* *************** ************@mi crosoft.com...
Hello,

I am declaring an element like this:
public static List<myListElem entmyList = new List<myListElem ent>();

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<myListElem ent>[] myList = new List<myListElem ent>[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<myListElem entmyList = new List<myListElem ent>();

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<myListElem ent>[] listArray = new List<myListElem ent>[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<myListElem ent>();
///

--
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
2405
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 relevant announcements. If you're interested, drop me a note. But if for some reason you think that this discussion is fine here at the c.l.py, please let me know. ** LONG POST AHEAD **
4
2829
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 that I can preform complicated operations against this data. The returned record count in these operations is always variable. 1. I have been using an arraylist.add function to handle non-multidemional returns but was wondering if I'm better...
19
3159
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 than in .Net environment, under VS 2005 Beta 2. Does anyone have any idea whether this will be addressed in the final release? Thanks, Tomasz
18
3259
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 storage and dynamically resize it when there is a new point or should I use ArrayList? Is speed noticable between the two? Regards,
6
6119
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 more minutes. 'REMOVE DUBLICATED VALUE FROM ARRAY +++++++++++++++++ Dim col As New Scripting.Dictionary Dim ii As Integer = 0
17
7263
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 to show the array data to the end user. Can I do that? How?
10
6585
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
5900
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 list. That part makes a reasonable amount of sense, as you can't actually take items away from an Array. However, there doesn't seem to be a way to perform the same operation in one fell swoop on a List<>. For example:
2
6174
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, like List<char>. What I have working is : Type type = newObj.GetType(); //newObj is what I'm trying to dump
0
9721
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
9601
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
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10378
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
9198
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
7653
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
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
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.