L
Lou
is a Hash Table equivalent to a VB6 Collection or Dictionary object?
-Lou
-Lou
William Ryan said:Both.
A hash table is derived from the System.Collections namespace. This is from
MSDN which is a good example on how to use one...
The first value is the Key, the second is the Value. I'm not sure what you
want to do so I gave a generic answer, but if you need something specific,
let me know and I'll do what I can to help you.
Cheers.
Bill
Hashtable phones = new Hashtable();
// Add items.
phones.Add("John", "123-4567");
phones.Add("Enju", "351-8765");
phones.Add("Molly", "221-5678");
phones.Add("James", "010-4077");
phones.Add("Nelly", "110-5699");
phones.Add("Leah", "922-5699");
// Iterate through the collection.
Console.WriteLine("Name\t\tNumber");
foreach (string name in phones.Keys)
{
Console.WriteLine(name +"\t"+ phones[name]);
}"Lou said:is a Hash Table equivalent to a VB6 Collection or Dictionary object?
-Lou
Lou said:I need to use collections, like class collections and just some generic
collections and am
not sure which is better, more efficiant etc. I noticed there are
"Collections"
"Dictionary"
"Hash Table"
and even some more.
why so many collections?
is there a reason to use one over another?
Thanks...
William Ryan said:Both.
A hash table is derived from the System.Collections namespace. This is from
MSDN which is a good example on how to use one...
The first value is the Key, the second is the Value. I'm not sure what you
want to do so I gave a generic answer, but if you need something specific,
let me know and I'll do what I can to help you.
Cheers.
Bill
Hashtable phones = new Hashtable();
// Add items.
phones.Add("John", "123-4567");
phones.Add("Enju", "351-8765");
phones.Add("Molly", "221-5678");
phones.Add("James", "010-4077");
phones.Add("Nelly", "110-5699");
phones.Add("Leah", "922-5699");
// Iterate through the collection.
Console.WriteLine("Name\t\tNumber");
foreach (string name in phones.Keys)
{
Console.WriteLine(name +"\t"+ phones[name]);
}"Lou said:is a Hash Table equivalent to a VB6 Collection or Dictionary object?
-Lou
William Ryan said:Dictionary's and hashtables are collections. So are arraylists. Typically,
you'd use a collection and strongly type it so you enforce what it's members
are. A hash Table for instace, allows you to effiiciently find members
without having to iterate through them. ArrayLists for instance necessitate
that you iterate through them to find a given member. Hash Tables don't let
you iterate the same way. You could store whatever object in most of those
structures...they are more alike then different.
If You need to use collections, any of those will techincally meet the
requirement. Think of it like this. If the boss said I need a Person to
accomplish something, a Canadian, American or Mexican might be better suited
to a task (for instance, a Mexican might be better at Spanish interpretation
or languge specific task) but all three of the people are in fact 'Person's.
So you would meet the requirement whichever you chose.
Lou said:I need to use collections, like class collections and just some generic
collections and am
not sure which is better, more efficiant etc. I noticed there are
"Collections"
"Dictionary"
"Hash Table"
and even some more.
why so many collections?
is there a reason to use one over another?
Thanks...
isWilliam Ryan said:Both.
A hash table is derived from the System.Collections namespace. This
fromwhatMSDN which is a good example on how to use one...
The first value is the Key, the second is the Value. I'm not sure
youwant to do so I gave a generic answer, but if you need something specific,
let me know and I'll do what I can to help you.
Cheers.
Bill
Hashtable phones = new Hashtable();
// Add items.
phones.Add("John", "123-4567");
phones.Add("Enju", "351-8765");
phones.Add("Molly", "221-5678");
phones.Add("James", "010-4077");
phones.Add("Nelly", "110-5699");
phones.Add("Leah", "922-5699");
// Iterate through the collection.
Console.WriteLine("Name\t\tNumber");
foreach (string name in phones.Keys)
{
Console.WriteLine(name +"\t"+ phones[name]);
is a Hash Table equivalent to a VB6 Collection or Dictionary object?
-Lou
Lou said:I need to use collections, like class collections and just some
generic collections and am
not sure which is better, more efficiant etc. I noticed there are
"Collections"
"Dictionary"
"Hash Table"
and even some more.
why so many collections?
is there a reason to use one over another?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.