473,545 Members | 2,444 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<ulon g,DelegateTyep> dictionary = new ...

and use dictionary object such as

dictionary [aUlongNumber] += aDelegateTyepOb ject;

then compiler is ok ,but throw KeyNotFoundExce ption 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(Delega te.Combine)?

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


The same as always; += expands to

dictionary[aUlongNumber] = dictionary[aUlongNumber] +
aDelegateTypeOb ject;

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
15909
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 find the key. In the example below, accessing the dictionary by using the exact key object that was used to add to the dictionary works. (see code...
8
17728
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, MyAbstractClass> { get { return _dictionary; } //error: no implicit conversion. }
12
21333
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 custom control. Thanks, Brett
5
1778
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> dict; ..... foreach(A key in dict.Keys) {
6
1803
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 Dictionary<string, FileStreamDict { get { return this.dict; } } The problem with this implementation is that I only want to give
2
5865
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 dictionary essentially creates the following array: Key Value
4
5130
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
1357
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
1486
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. Thanks in advance for all your help.
0
7425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7682
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. ...
0
7935
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7449
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...
0
6009
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...
0
5069
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1911
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
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.