473,499 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#2.0 Dictionary<Key,Value> indexer operation is strange?

Hi ,

I use VS 2005 beta1 to do some thing as follows.

declare a Dictionary<ulong,DelegateTyep> dictionary = new ...

and use dictionary object such as

dictionary [aUlongNumber] += aDelegateTyepObject;

then compiler is ok ,but throw KeyNotFoundException at run-time.
OK,I think just a missed initailization,thne add it like

dictionary[aUlongNumber] = null;

It becomes to be vary strange.It doesn't throw exception any more.

What's difference between '=' and '+=' on Dictionary's indexer operation?
Them are also assigning value to indexing entry,right?
Or some thiing compiler do for '+=' operator(Delegate.Combine)?

Thanks for your help
Nov 16 '05 #1
1 2269
What's difference between '=' and '+=' on Dictionary's indexer operation?


The same as always; += expands to

dictionary[aUlongNumber] = dictionary[aUlongNumber] +
aDelegateTypeObject;

and retrieving dictionary[aUlongNumber] before you have added that key
to the dictionary will throw an exception.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2

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

Similar topics

2
15881
by: ESPNSTI | last post by:
Hi, I'm trying to use a generics dictionary with a key class that implements and needs IComparable<>. However when I attempt to use the dictionary, it doesn't appear to use the IComparable<> to...
8
17714
by: Brian P | last post by:
I want to expose a property of Dictionary<string, MyAbstractClass>. I tried to do it this way: private Dictionary<string, MyChildClass> _dictionary; public Dictionary<string,...
12
21304
by: Brett Romero | last post by:
If I want to take action on the Add event of a generic Dictionary, do I need to create a custom Dictionary and add an event handler for the Add() method? The dictionary is a public field on a...
5
1767
by: Brian Richards | last post by:
I'm experiencing some wierd behavior with a Dictionary<T,U> class using foreach loops, such that the Key returned in the foreach is not contained in the dictionary. code: Dictionary<A, B>...
6
1800
by: daohuy.hua | last post by:
The context is that I have a C# class named MainModel which has a private Dictionary<string, FileStreammember named dict. I also have a property Dict to access to this member: public...
2
5852
by: Assimalyst | last post by:
Hi I have a Dictionary<string, List<string>>, which i have successfully filled. My problem is I need to create a filter expression using all possible permutations of its contents. i.e. the...
4
5126
by: =?Utf-8?B?YW1pcg==?= | last post by:
do i have to remove the pair and then reinsert it or can i just update the value of the dictionary
6
1353
by: Tony | last post by:
Hello! When you are using a Dictionary object what type is to possible to have on the key? //Tony
4
1474
by: =?Utf-8?B?YW1pcg==?= | last post by:
how can I access the first item of a dictionary where the datatype for the Key is not known to me? I tried the array index 0 and taht did not work because the key is not of integer type. ...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
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...
0
7390
tracyyun
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...
0
5475
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,...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
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...

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.