If your collection contains elements of only one data type, you can use one of the classes in the System. Generic namespace.
A generic collection enforces type safety so that no other data type can be added to it. When you retrieve an element from a generic collection, you do not have to determine its data type or convert it. For the examples in this topic, include Imports statements for the System. Generic and System. Linq namespaces. The following example creates a list of strings and then iterates through the strings by using a For Each…Next statement.
If the contents of a collection are known in advance, you can use a collection initializer to initialize the collection. For more information, see Collection Initializers. The following example is the same as the previous example, except a collection initializer is used to add elements to the collection. You can use a For…Next statement instead of a For Each statement to iterate through a collection.
You accomplish this by accessing the collection elements by the index position. The index of the elements starts at 0 and ends at the element count minus 1. The following example iterates through the elements of a collection by using For…Next instead of For Each. The following example removes elements from a generic list.
Instead of a For Each statement, a For…Next statement that iterates in descending order is used. This is because the RemoveAt method causes elements after a removed element to have a lower index value. Many common collections are provided by the. NET Framework. Each type of collection is designed for a specific purpose.
Generic classes. Concurrent classes. Collections classes. You can create a generic collection by using one of the classes in the System. A generic collection is useful when every item in the collection has the same data type. A generic collection enforces strong typing by allowing only the desired data type to be added. The following table lists some of the frequently used classes of the System. Generic namespace:.
In the. NET Framework 4 or newer, the collections in the System. Concurrent namespace provide efficient thread-safe operations for accessing collection items from multiple threads. The classes in the System. Concurrent namespace should be used instead of the corresponding types in the System. Collections namespaces whenever multiple threads are accessing the collection concurrently.
For more information, see Thread-Safe Collections and System. Some classes included in the System. To bring you up to speed with Visual Basic , this practical book offers nearly 50 hands-on projects. This book is for the dilettante, and aimed at anyone who is interested in learning VB. The approach that has been followed here is that simple applications are built first, and then, the code is deciphered to unveil the internal workings of the product.
Upgrading Microsoft Visual Basic 6. Free full VB. It explains the very basics of the language with screenshots showing what is expected to see during development process. It does not cover every aspect of the language. It covers many different techniques and topics including optimization of programs, object oriented programming and coding guidelines, Windows API, VB6 command reference, and much more.
Each one explores a new feature of the language, with emphasis on changes that can increase productivity, simplify programming tasks, and help you add new functionality to your applications. The text includes the installation of Visual Studio, variable types, flow control, string manipulation, database access, form designing, graphics, arrays, and much more.
0コメント