Home > 2010 Winter BTI420 > Collection classes, including arrays, introduction

Collection classes, including arrays, introduction

January 25, 2010 Leave a comment Go to comments

In the "StringFun" code example, you saw a .NET Framework array declared and used. In the examples that used list controls, you saw the Items collection. So, now it’s time to discuss collection classes in general, and some of them in more detail.

 

Collection classes enable you to work with collections of types. The collection can be organized as an array, which is very familiar to you, or as some other kind of collection. 

 

Arrays

In your code, you can make an array of any type. Just add the [] syntax to the type name in the declaration.

When processing an array’s members, you typically use an element accessor/enumerator, similar to what you’ve seen in other languages and platforms.

Consult the documentation for initialization options, and for common methods and properties.

 

A collection type that you have seen – "Items" in a list control

The list controls you have worked with – DropDownList, ListBox, CheckBoxList, RadioButtonList – have an "Items" collection.

A collection of what? ListItem.

When processing a collection’s members, you typically use an enumerator of the member type. If you want to process all of the members, you typically use foreach syntax. Otherwise, you can use a method to locate the member that you want.

Consult the documentation for initialization options, and for common methods and properties.

 

Other collection types

The .NET Framework offers you a selection of specialized collection types. They include two types found in our example today – queue and stack.

Note that you need to bring System.Collections into scope to easily use them. Consult the documentation for initialization options, and for common methods and properties.

 


Advertisements
Categories: 2010 Winter BTI420
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: