Microsoft 9GD00001 ユーザーズマニュアル

ページ / 449
 
110
 
Microsoft Visual Studio 2010: A Beginner’s Guide
In .NET, the generic List type is declared as List<T>, or List(Of T) in VB. The T is a 
type placeholder, where you can specify any type you want. For example, you could create 
List<int> for integers or a List<string> for strings, which would be List(Of Integer) 
and List(Of String) in VB, respectively. In Listing 4-8, you can see that checkAccts is 
declared as List<Checking> (List(Of Checking) in VB). Since a list grows dynamically 
to accommodate any number of elements, you use the Add method to add elements to the 
List.
 Once elements are in the List, you can use element access syntax, as shown in the for 
loop, to access the elements one at a time. Collections such as List are convenient because 
they have multiple convenience methods, such as Clear, Contains, Remove, and more.
In addition to List, the System.Collections.Generic namespace has several other 
generic collections, such as Dictionary, Queue, and Stack. Each generic is initialized by 
replacing the type parameters with the types you want to work on and then by using the 
specialized methods of that collection. Whenever you see the type parameter syntax, you 
should recognize that a generic is being used and you will have an idea of what the code 
means and how to read it in the documentation.
Summary
What you learned in this chapter were essential skills for upcoming chapters in the 
rest of the book. Knowing how delegates and events work helps you with event-driven 
development that is common to GUI application development. Understanding interfaces 
directly relates to being able to build Web services, among other uses. You’ll also make 
regular usage of arrays and generics, and this chapter gave you the essentials to know 
what collections are.
Remember that this was only an introduction to C# and VB and that there is much 
more to learn about these languages. Of course, this book is about VS and not languages, 
so the next chapter is where you’ll learn to build VS projects.