473,405 Members | 2,349 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,405 software developers and data experts.

List definition

I have the following code:
***************************************
public class Test
{
....

public static TestCollection MyNewCollection()
{
}
}

// Define Collections here
public class TestCollection : List<Test>
************************************

What is this doing here?

I assume that I have a class of Test and the last line allows me to make
class that is just a collection (array) of objects of type Test.

Is that what is happening here?

I then saw some code that did something like:

....
List<TestmyList:
....

Which would define "myList" as a collection of objects of type Test?

Is this what is happening?

Thanks,

Tom
Dec 13 '07 #1
1 2095
On Thu, 13 Dec 2007 11:07:38 -0800, tshad <ts***@dslextreme.comwrote:
[...]
// Define Collections here
public class TestCollection : List<Test>
************************************

What is this doing here?

I assume that I have a class of Test and the last line allows me to make
class that is just a collection (array) of objects of type Test.

Is that what is happening here?
The last line creates a new class that _inherits_ the List<Testclass.
The List<Testclass itself is a concrete version of the generic List<T>
class, which is not exactly an array. It's sort of a merged version of
Array and ArrayList, with typed elements like an Array has, but with the
dynamic features of ArrayList.

By inheriting it, the TestCollection class can add its own functionality
to the base List<Testbehavior. I would not bother inheriting List<Test>
unless that extension was specifically needed or desired. You might as
well just use List<Testdirectly instead.
I then saw some code that did something like:

...
List<TestmyList:
...

Which would define "myList" as a collection of objects of type Test?
Yes. It declares myList as a specific kind of collection of objects of
type Test. .NET has a wide variety of collection types, and the generic
List<Ttype is just one of them.

Perhaps more important for you to understand is that the "<T>" part is not
unique to collections. The collection classes happen to be one of the
more prominent uses of generics in the framework, but generics are not
used solely for collections. So in that example, it's the "List" part
that is the important thing with respect to the type being a collection;
the "<Test>" part is just part of the way you declare that particular kind
of collection (that is, using a generic class).

Pete
Dec 13 '07 #2

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

Similar topics

2
by: Steve | last post by:
Hi, I have a very long string, someting like: DISPLAY=localhost:0.0,FORT_BUFFERED=true, F_ERROPT1=271\,271\,2\,1\,2\,2\,2\,2,G03BASIS=/opt/g03b05/g03/basis,...
57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
2
by: gencode | last post by:
How do I get the list of overrides for a ASP.NET page in C# I can get my PageEvent by selecting MyPage System.Web.UI.Page and selecting the Lightingbolt, that gives me a list of page events like...
43
by: michael.f.ellis | last post by:
The following script puzzles me. It creates two nested lists that compare identically. After identical element assignments, the lists are different. In one case, a single element is replaced. In...
5
by: Bryan | last post by:
Hi, Where is the proper place to use a member initialization list, the header or cpp file? Does it make any difference? Also, is there any difference between using a member initialization...
2
by: menyki | last post by:
error c: ......line 3: unable to open include file 'stdio.h error c: ....... line 4: unable to open include file 'stdlib.h' error c: ........line 5: unable to open include file 'time.h' error c:...
3
by: maruf.syfullah | last post by:
Consider the following Class definitions: class AClass { int ai1; int ai2; public: CClass* c; AClass(){}
6
by: Timur Tabi | last post by:
Is there a way I can have the browser automatically insert a blank line after each definition in a definition list? Right now I have this: term-1 definition text .... term -2 definition text...
36
by: pereges | last post by:
Hi, I am wondering which of the two data structures (link list or array) would be better in my situation. I have to create a list of rays for my ray tracing program. the data structure of ray...
11
by: Juha Nieminen | last post by:
Assume we have this: std::list<Typelist1(10, 1), list2(20, 2); std::list<Type>::iterator iter = list1.end(); list1.swap(list2); What happens here, according to the standard? 1) 'iter'...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...

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.