I.T. Discussion Community!
-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

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

   ► KBProgrammingVB.NetLanguage Basics   Print This     
 
VB.Net Language Basics:
VB.Net Associative Array (Dictionary)
 
Posted 9 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

1 Comments.
Share a thought or comment...
Comment 1 of 1

To the extent which is the better one, it's progressively a matter of coding standard, as well as individual inclination.  Considering what sort of holder to utilize, you should utilize just those from System.Collection.Generics in .NET unless you are constrained something else. What's more, Dictionary is the default cooperative container.
customwritingcompany.com answers your questions professionally.

Posted 9 days ago
 
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 = P1215A1
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 _
Collection(Of String, String)
  
States("CA") = "California"
States("NV") = "Nevada"
 
MsgBox(States.Item("NV"))
3. 
//Imports System.Collections.Generic
Dim States As New _
Dictionary(Of String, String)

States.Add("CA", "California")
States.Add("NV", "Nevada")
 
MsgBox(States("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
14391
Since 11/4/2008
-
   Contact Us!
 
PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

1,591 People Online Now!!  
Sign In to see who's online now!  Not a member? Join now. It's free!
Show more stats...


©1995-2017 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech