Default value for uninitialized hash key
Like in Perl, if a hash key is uninitialized then if you perform the below code
$hash{$key} =~ $hash{$key}++
then the value for that particular key increases to 1 (cause, it's first undefined开发者_开发知识库 and then as per the context, here it's numaical ... it takes the value to 0 ... increases it to 1).
My question is, does the same concept follows in case of C# as well? I mean, if I perform the above code in c# what would be the result? Will it be 1 or what?
Any idea?
Thanks, Rahul
That bit of code makes no sense.
If you want to know if the key exists in the hash:
if (exists $hash{$key}) { ... }
If you want to know if it has a value defined:
if (defined $hash{$key}) { ... }
If you want to increment the value,
$hash{$key}++
As it is, you're attempting to do a regex match in a rather nonsensical way.
OOPS!!! Sorry ... I got it; actually the Perl code mentioned is meant to check/confirm whether the particular "KEY" exist or not ... OR sort of that.
So, in C# I cna just check for "hashtable.containskey(key)" ... that will do the trick.
Thanks.
精彩评论