Skip to main content Accessibility help
×
Hostname: page-component-7479d7b7d-rvbq7 Total loading time: 0 Render date: 2024-07-15T07:56:42.991Z Has data issue: false hasContentIssue false

Chapter 2 - Arrays and ArrayLists

Published online by Cambridge University Press:  05 June 2012

Michael McMillan
Affiliation:
Pulaski Technical College, Arkansas
Get access

Summary

The array is the most common data structure, present in nearly all programming languages. Using an array in C# involves creating an array object of System.Array type, the abstract base type for all arrays. The Array class provides a set of methods for performing tasks such as sorting and searching that programmers had to build by hand in the past.

An interesting alternative to using arrays in C# is the ArrayList class. An arraylist is an array that grows dynamically as more space is needed. For situations where you can't accurately determine the ultimate size of an array, or where the size of the array will change quite a bit over the lifetime of a program, an arraylist may be a better choice than an array.

In this chapter, we'll quickly touch on the basics of using arrays in C#, then move on to more advanced topics, including copying, cloning, testing for equality and using the static methods of the Array and ArrayList classes.

ARRAY BASICS

Arrays are indexed collections of data. The data can be of either a built-in type or a user-defined type. In fact, it is probably the simplest just to say that array data are objects. Arrays in C# are actually objects themselves because they derive from the System.Array class. Since an array is a declared instance of the System.Array class, you have the use of all the methods and properties of this class when using arrays.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2007

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Arrays and ArrayLists
  • Michael McMillan, Pulaski Technical College, Arkansas
  • Book: Data Structures and Algorithms Using C#
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511804793.003
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Arrays and ArrayLists
  • Michael McMillan, Pulaski Technical College, Arkansas
  • Book: Data Structures and Algorithms Using C#
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511804793.003
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Arrays and ArrayLists
  • Michael McMillan, Pulaski Technical College, Arkansas
  • Book: Data Structures and Algorithms Using C#
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511804793.003
Available formats
×