473,657 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strict type for Hashtable?

I thought that arrays and hash tables could be strictly typed under 2.0
instead of just being objects, but I can't find any documentation.

I want to have the values in a hash table designated as a string type,
so that I don't have to keep doing something like:

strSomething = CStr(hashtable( Key))

I'd rather have
strSomething = hashtable(Key)

Do the hashtables support this? If they do, what is the syntax?

Thanks,
Shane

Jul 13 '06 #1
3 1471
Hello Shane,

Check out the System.Collecti ons.Generic namespace and look up the documentation
on the new "Of" keyword.

-Boo
I thought that arrays and hash tables could be strictly typed under
2.0 instead of just being objects, but I can't find any documentation.

I want to have the values in a hash table designated as a string type,
so that I don't have to keep doing something like:

strSomething = CStr(hashtable( Key))

I'd rather have
strSomething = hashtable(Key)
Do the hashtables support this? If they do, what is the syntax?

Thanks,
Shane

Jul 14 '06 #2
Yes, but the generic hashtable is the Dictionary(Of T) in the
System.Collecti ons.Generic namespace.
e.g.,
Dim GenericHashtabl e As New Dictionary(Of String)
GenericHashtabl e.Add(somekey, somestring)
Dim thisString = GenericHashtabl e(somekey)

(also, List(Of T) is the generic replacement for ArrayList in 2.0)
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#
"Shane" wrote:
I thought that arrays and hash tables could be strictly typed under 2.0
instead of just being objects, but I can't find any documentation.

I want to have the values in a hash table designated as a string type,
so that I don't have to keep doing something like:

strSomething = CStr(hashtable( Key))

I'd rather have
strSomething = hashtable(Key)

Do the hashtables support this? If they do, what is the syntax?

Thanks,
Shane

Jul 14 '06 #3
Thanks for the info guys.

This feature was one of the items that had me chomping at the bit to
upgrade to 2.0

Shane

Jul 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1678
by: Vinay Agarwal | last post by:
Hello, I am using Hashtable class in my application to store key/value pairs. It works great except the types returned are all objects. As a result, there are type-casts everywhere making the code very hard to read. I believe it should be relatively easy to derive a class from Hashtable that returns appropriate types for my application. I started writing it like this public class PeerTable : Hashtable { public new PeerTable Clone() {
10
11783
by: Bob | last post by:
This has been bugging me for a while now. GetType isn't availble for variables decalred as interface types, I have to DirectCast(somevariable, Object). In example: Sub SomeSub(ByVal Dictionary as IDictionary) If Dictionary is Nothing Then Return Dim o as Object = DirectCast(Dictionary, Object)
8
1823
by: Rich | last post by:
Hello, If I leave Option Strict Off I can use the following syntax to read data from a Lotus Notes application (a NotesViewEntry object represents a row of data from a Lotus Notes View - like a record in a sql Server view) .... Dim entry As Domino.NotesViewEntry Dim obj As Object str1 = entry.ColumnValues(0)
4
3007
by: Howard Kaikow | last post by:
I am trying to retrive some WMI properties using Option Strict On. This requires the use of InvokeMember. I know that there are alternative ways to get the values, but I want to learn how to use WMI with InvokeMember and Option Strict On. I'm getting an "Unknown Name" error in the following statement in the code below. objProp = typeObjProps.InvokeMember("Item", _
4
1350
by: zacks | last post by:
A common programming technique I use in VB is making a collection of structures. But if Option Strict is on (which I would prefer), the .Add that adds the structure to the collection is flagged with a compiler error (invalid type conversion). Is there a way to use a collection of structures WITH the Option Strict On?
9
2324
by: YYZ | last post by:
After reading many messages in this group, it seems that the preferred setting for this is ON. Okay, I did that in my project (first with ..Net -- long time VB6 developer) and now a bunch of problems have cropped up. Most are easy to solve with using an explicit type cast cType(whatever, whatever type), but some aren't. Situation 1: I've got code that tries to get the itemkey of the selected item in a combobox....
3
1071
by: Rich | last post by:
This code worked before I added option strict. But I should do it correctly. option ... option Strict On Public Structure Itm Dim mailSvr As String ... Public Sub New(ByVal a1 As String...) mailSvr = a1
4
1419
by: John | last post by:
Hi, I derived a class from the Hashtable class, with ISerializable implemented and the tag added. Everything works fine with one exception. I store the hashtable in ViewState, but on a postback, the object in ViewState changes to Hashtable, instead of MyHashtable. I'm assuming this is a simple serialization setting, but I can't seem to
0
1414
by: Rajesh | last post by:
I am trying to use a simple custom type for saving the profile information of a user. The custom class inherits from the Hashtable. I am serializing the type as "Binary" in the provider sections of the web.config. When I add a key-value to the custom type, I can see that its being saved in the database (aspnet_profiles table - PropertyValuesBinary column). But, when I want to read the information in the profile, my custom type object is...
0
8397
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7333
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.