IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
VB.Net
Search VB.Net Group:

Advanced
-Collapse +Expand VB.Net To/From
To/FromCODEGuides
-Collapse +Expand VB.Net Store
PRESTWOODSTORE

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingVB.NetLanguage Basics   Print This     
 
VB.Net Language Basics:
VB.Net Associative Array (Dictionary)
 
Posted 16 years ago on 11/4/2008 and updated 1/20/2009
VB.Net Code Snippet:
 A flashcard from our VB.Net Flashcards Library
 A code snippet from our VB.Net Code Snippets Page

KB101520

General Info: Associative Array

A set of unique keys linked to a set of values. Each unique key is associated with a value. Think of it as a two column table. MyArray['CA'] = 'California' MyArray['AR'] = 'Arizona'

Languages Focus: Associative Array

Associative arrays are also known as a dictionary or a hash table in other languages.

VB.Net Associative Array

An associative array links a set of keys to a set of values. In Visual Basic, associative arrays are implemented as Dictionaries.

This code produces a message box saying "Nevada."

Syntax Example:
//Imports System.Collections.Generic
Dim States As New Dictionary(Of String, String)

States.Add("CA", "California")
States.Add("NV", "Nevada")
 
MsgBox(States("NV"))


About Associative Array
A set of unique keys linked to a set of values. Each unique key is associated with a value. Think of it as a two column table. MyArray['CA'] = 'California' MyArray['AR'] = 'Arizona'

More Info

Definition:  Associative Array
Code:  Associative Arrays in Visual Basic (a Dictionary)

Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P194A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Intermediate

1 Intermediate Level Question

Question #1: Multiple Choice

Which code snippet is the correct syntax for declaring and using an associative array?

Answer:
1. 
//Imports System.Collections.Generic
Dim States As New Collection

States.Add("CA", "California")
States.Add("NV", "Nevada")
 
MsgBox(States("NV"))
2. 
//Imports System.Collections.Generic
Dim States As New _
Dictionary(Of String, String)

States.Add("CA", "California")
States.Add("NV", "Nevada")
 
MsgBox(States("NV"))
3. 
//Imports System.Collections.Generic
Dim States As New _
Collection(Of String, String)
  
States("CA") = "California"
States("NV") = "Nevada"
 
MsgBox(States.Item("NV"))
4. 
//Imports System.Collections.Generic
Dim States As New Collection(Of String)

States.Add("CA", "California")
States.Add("NV", "Nevada")
 
MsgBox(States.Item("NV"))
5. 
//Imports System.Collections.Generic
Dim States As New Array(String, String)

States.Add("California", "CA")
States.Add("Nevada", "NV")
 
MsgBox(States.ListItem("NV"))

 KB Article #101520 Counter
19601
Since 11/4/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]