I bet I know the answer already.
I have a hashtable (hMaster) that holds several hashtables ("hTables") each
of which holds other hashtables ("hColumns") . Presently, I am getting at
the info I want thusly (this compiles, at least):
Hashtable hTable = (Hashtable)hMas ter[tableName];
Hashtable hColumn = (Hashtable)hTab le[columnName];
return hColumn.Contain sKey(codeValue) ;
This is kind of cumbersome. I'd rather use something like this:
return hMaster[tableName].[columnName].ContainsKey(co deValue);
But this syntax is not supported. I'm not surprised by this, I was asking a
lot, but maybe there is a cleaner approach than what I'm actually using with
all the steps and casts?
Matt
(P.S. I realize I could have leveraged ADO.NET dataset stuff to check my
code values. But I'm not up to speed on all the fancy DataSet/DataTable
stuff, so I stuck with what made sense to me. Also I had the idea that keys
from Hashtables would be faster, there's going to be a lot of these
validations.) 4 10386
Why not:
<snip>
return
((Hashtable)((H ashtable)hMaste r[tableName]).[columnName]).ContainsKey(c odeVa
lue);
</snip>
Still a bit cumbersome so it might not be what you were looking for.
Another solution would be to create a object that inherits from Hashtable
and override the indexer so that it can only contain Hashtable objects and
therefore will be strongly typed and won't require the type casting.
Patrick Altman
"Matt C." <ca*****@my-deja.com> wrote in message
news:Xn******** *************** *******@207.46. 248.16... I bet I know the answer already.
I have a hashtable (hMaster) that holds several hashtables ("hTables")
each of which holds other hashtables ("hColumns") . Presently, I am getting at the info I want thusly (this compiles, at least):
Hashtable hTable = (Hashtable)hMas ter[tableName]; Hashtable hColumn = (Hashtable)hTab le[columnName]; return hColumn.Contain sKey(codeValue) ;
This is kind of cumbersome. I'd rather use something like this:
return hMaster[tableName].[columnName].ContainsKey(co deValue);
But this syntax is not supported. I'm not surprised by this, I was asking
a lot, but maybe there is a cleaner approach than what I'm actually using
with all the steps and casts?
Matt
(P.S. I realize I could have leveraged ADO.NET dataset stuff to check my code values. But I'm not up to speed on all the fancy DataSet/DataTable stuff, so I stuck with what made sense to me. Also I had the idea that
keys from Hashtables would be faster, there's going to be a lot of these validations.)
Matt,
As suggested, you will have to use a cast. However, in .NET 2.0, with
Generics, you will be able to use the Generic Dictionary class, which will
be strongly typed, therefore eliminating the need for the cast.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Matt C." <ca*****@my-deja.com> wrote in message
news:Xn******** *************** *******@207.46. 248.16... I bet I know the answer already.
I have a hashtable (hMaster) that holds several hashtables ("hTables") each of which holds other hashtables ("hColumns") . Presently, I am getting at the info I want thusly (this compiles, at least):
Hashtable hTable = (Hashtable)hMas ter[tableName]; Hashtable hColumn = (Hashtable)hTab le[columnName]; return hColumn.Contain sKey(codeValue) ;
This is kind of cumbersome. I'd rather use something like this:
return hMaster[tableName].[columnName].ContainsKey(co deValue);
But this syntax is not supported. I'm not surprised by this, I was asking a lot, but maybe there is a cleaner approach than what I'm actually using with all the steps and casts?
Matt
(P.S. I realize I could have leveraged ADO.NET dataset stuff to check my code values. But I'm not up to speed on all the fancy DataSet/DataTable stuff, so I stuck with what made sense to me. Also I had the idea that keys from Hashtables would be faster, there's going to be a lot of these validations.)
Matt C. <ca*****@my-deja.com> wrote: I bet I know the answer already.
I have a hashtable (hMaster) that holds several hashtables ("hTables") each of which holds other hashtables ("hColumns") . Presently, I am getting at the info I want thusly (this compiles, at least):
Hashtable hTable = (Hashtable)hMas ter[tableName]; Hashtable hColumn = (Hashtable)hTab le[columnName]; return hColumn.Contain sKey(codeValue) ;
This is kind of cumbersome. I'd rather use something like this:
return hMaster[tableName].[columnName].ContainsKey(co deValue);
But this syntax is not supported. I'm not surprised by this, I was asking a lot, but maybe there is a cleaner approach than what I'm actually using with all the steps and casts?
Why are you surprised by this? hMaster[tableName] is of type Object,
not Hashtable. There's nothing to stop you putting something completely
different in hMaster.
Generics in 2.0 will help you here, as you'll be able to tell the
compiler that hTable is a Dictionary<stri ng,Dictionary<s tring,object>>
or whatever.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Patrick Altman" <paltmanATgmail DOTcom> wrote in
news:#X******** ******@TK2MSFTN GP11.phx.gbl: Why not:
<snip> return ((Hashtable)((H ashtable)hMaste r[tableName]).[columnName]).ContainsKey(c o deVa lue); </snip>
Still a bit cumbersome so it might not be what you were looking for.
Sweet. Thanks.
(You actually have to remove the dot between tableName and columnName, for
anyone else making use of this. My fault, I started us down that road.)
That is unlovely to read, but it does get rid of the temp variables which is
what I was really after.
I'm assuming the inline casting is actually going to be a little faster than
creating the temp Hashtable and assigning the internal Hashtables one step
at a time. But I'm not sure of that; maybe they amount to the same thing
once compiled. Does anyone know offhand if the nested parenthetical casting
above is faster than using temp variables in separate steps?
Matt
P.S. Thanks to those who pointed out generics in .NET 2.0. I'm looking
forward to those, this is only about the 100th time they would have come in
handy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JezB |
last post by:
How can I loop thru a hashtable changing the Value of each entry ? Whatever
I try I always seem to get the error about modifying the collection within
the loop.
|
by: Ken |
last post by:
I have a C# Program where multiple threads will operate on a same Hashtable.
This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable)
method, so no further Lock statements are used before adding, removing or
iterating the Hashtable. The program runs in a high workload environment.
After running a few days, now it suddenly catchs this Exception when
inserting a pair of key and object,
stacktrace =...
|
by: Robin Tucker |
last post by:
When I create a hashtable hashing on Object-->Item, can I mix "string" and
"integer" as the key types? I have a single thumbnail cache for a database
with (hashed on key) and a file view (hashed on string). So, for example,
when I want to know if the file "xyz.abc" is in the cache, I can write
myTable.ContainsKey ( "xyz.abc" ) or if a given DB key is in the hash I can
write myTable.ContainsKey ( 123 ). Or do the keys all have to be of...
|
by: Dick |
last post by:
Hello,
I'm trying to serialize a class with a Hashtable within:
' Class code:
Imports System.Collections
Class clsOptions
Public countID As Integer
Public persons As New Hashtable
End Class
|
by: bandroo |
last post by:
Hi Guys
How can I modify the items within a hashtable "in situ" so to speak?
At the moment, I am locating the item that I want, extracting it,
modifying the item, deleting the hashtable item, and then adding back
the modified item to hashtable.
This seems rather long winded, and surely there must be a simpler way
than that.
| |
by: raylopez99 |
last post by:
Hello all—
I’m trying to get the below to work and cannot get the format right.
It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx
What it is: I’m trying to store multicast delegates in a hash table,
and then fire the delegates one of two ways (after registering/
creating the delegates, etc).
|
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
| |
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |