Click here to Skip to main content
15,917,320 members
Home / Discussions / C#
   

C#

 
GeneralRe: T9 dictionary in c# Pin
Not Active25-Jun-07 5:11
mentorNot Active25-Jun-07 5:11 
AnswerRe: T9 dictionary in c# Pin
Dan Neely25-Jun-07 5:21
Dan Neely25-Jun-07 5:21 
QuestionObject as disctionary key Pin
AndrusM25-Jun-07 1:36
AndrusM25-Jun-07 1:36 
I need to implement object in-memory cache .

Each object id can be composed from several string, integer and decimal type values.

ContainsKey does not find existing key in this case.

How to force ContainsKey to compare object contents and find key?
Should i use binaryformatter to serialize CacheKey, overload CacheKey == operator or any other idea ?

To reproduce,

run the code.

Observed:

Key not found

Expected:

Key found


using System.Collections.Generic;<br />
<br />
class test {<br />
	struct CacheKey {<br />
		object Key;<br />
		public CacheKey(object key) {<br />
			Key = key;<br />
		}<br />
	}<br />
<br />
	static Dictionary<CacheKey, object> Cache =<br />
				new Dictionary<CacheKey, object>();<br />
<br />
	static void Main() {<br />
		CacheKey key = new CacheKey(new object[] { "test1", 1 });<br />
		Cache.Add(key, "");<br />
		CacheKey key2 = new CacheKey(new object[] { "test1", 1 });<br />
		if (!Cache.ContainsKey(key2))<br />
			System.Windows.Forms.MessageBox.Show("Key not found");<br />
		else<br />
			System.Windows.Forms.MessageBox.Show("Key found");<br />
	}<br />
}


Andrus

AnswerRe: Object as disctionary key Pin
originSH25-Jun-07 1:48
originSH25-Jun-07 1:48 
GeneralRe: Object as disctionary key Pin
AndrusM25-Jun-07 2:36
AndrusM25-Jun-07 2:36 
GeneralRe: Object as disctionary key Pin
Pete O'Hanlon25-Jun-07 3:01
mvePete O'Hanlon25-Jun-07 3:01 
GeneralRe: Object as disctionary key Pin
AndrusM25-Jun-07 3:16
AndrusM25-Jun-07 3:16 
AnswerRe: Object as disctionary key Pin
Guffa25-Jun-07 4:05
Guffa25-Jun-07 4:05 
GeneralRe: Object as disctionary key Pin
AndrusM25-Jun-07 4:27
AndrusM25-Jun-07 4:27 
AnswerRe: Object as disctionary key Pin
Guffa25-Jun-07 7:51
Guffa25-Jun-07 7:51 
GeneralRe: Object as disctionary key Pin
AndrusM26-Jun-07 0:05
AndrusM26-Jun-07 0:05 
AnswerRe: Object as disctionary key Pin
Guffa26-Jun-07 2:13
Guffa26-Jun-07 2:13 
GeneralRe: Object as disctionary key Pin
AndrusM26-Jun-07 4:47
AndrusM26-Jun-07 4:47 
AnswerRe: Object as disctionary key Pin
Guffa26-Jun-07 6:08
Guffa26-Jun-07 6:08 
GeneralRe: Object as disctionary key Pin
originSH25-Jun-07 4:30
originSH25-Jun-07 4:30 
GeneralRe: Object as disctionary key Pin
AndrusM25-Jun-07 5:31
AndrusM25-Jun-07 5:31 
GeneralRe: Object as disctionary key Pin
originSH25-Jun-07 5:45
originSH25-Jun-07 5:45 
QuestionThe modifier 'public' is not valid for this item. Pin
steffw25-Jun-07 1:35
steffw25-Jun-07 1:35 
AnswerRe: The modifier 'public' is not valid for this item. Pin
originSH25-Jun-07 1:52
originSH25-Jun-07 1:52 
GeneralRe: The modifier 'public' is not valid for this item. Pin
steffw25-Jun-07 2:54
steffw25-Jun-07 2:54 
AnswerRe: The modifier 'public' is not valid for this item. Pin
Guffa25-Jun-07 5:36
Guffa25-Jun-07 5:36 
Questiongetting id of row Pin
tauras8125-Jun-07 1:26
tauras8125-Jun-07 1:26 
AnswerRe: getting id of row Pin
Sathesh Sakthivel25-Jun-07 1:32
Sathesh Sakthivel25-Jun-07 1:32 
AnswerRe: getting id of row Pin
Revathij25-Jun-07 1:59
Revathij25-Jun-07 1:59 
QuestionHow to view a RPT file in my application Pin
i.rabek25-Jun-07 1:26
i.rabek25-Jun-07 1:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.