Click here to Skip to main content
15,914,070 members
Home / Discussions / C#
   

C#

 
QuestionPreventing Form Focus Pin
kmuthuk5-Jan-07 8:11
kmuthuk5-Jan-07 8:11 
AnswerRe: Preventing Form Focus Pin
Luc Pattyn5-Jan-07 8:39
sitebuilderLuc Pattyn5-Jan-07 8:39 
GeneralRe: Preventing Form Focus Pin
kmuthuk5-Jan-07 12:02
kmuthuk5-Jan-07 12:02 
GeneralRe: Preventing Form Focus Pin
Luc Pattyn5-Jan-07 12:50
sitebuilderLuc Pattyn5-Jan-07 12:50 
GeneralRe: Preventing Form Focus Pin
kmuthuk10-Jan-07 3:25
kmuthuk10-Jan-07 3:25 
QuestionChar problem Pin
CodeItWell5-Jan-07 7:09
CodeItWell5-Jan-07 7:09 
AnswerRe: Char problem Pin
Ravi Bhavnani5-Jan-07 7:17
professionalRavi Bhavnani5-Jan-07 7:17 
GeneralRe: Char problem Pin
CodeItWell5-Jan-07 9:19
CodeItWell5-Jan-07 9:19 
GeneralRe: Char problem Pin
Ravi Bhavnani5-Jan-07 9:31
professionalRavi Bhavnani5-Jan-07 9:31 
GeneralRe: Char problem [modified] Pin
CodeItWell5-Jan-07 10:29
CodeItWell5-Jan-07 10:29 
GeneralRe: Char problem Pin
Ravi Bhavnani5-Jan-07 11:18
professionalRavi Bhavnani5-Jan-07 11:18 
QuestionC#.NET Email Pin
TRK@UK5-Jan-07 6:26
TRK@UK5-Jan-07 6:26 
AnswerRe: C#.NET Email Pin
Ravi Bhavnani5-Jan-07 6:36
professionalRavi Bhavnani5-Jan-07 6:36 
AnswerRe: C#.NET Email Pin
Guffa5-Jan-07 8:03
Guffa5-Jan-07 8:03 
GeneralRe: C#.NET Email Pin
Dan Neely5-Jan-07 8:26
Dan Neely5-Jan-07 8:26 
GeneralRe: C#.NET Email Pin
Guffa6-Jan-07 10:09
Guffa6-Jan-07 10:09 
QuestionGetting a random entry from a Generic Dictionary [modified] Pin
Mike Heffernan5-Jan-07 5:58
Mike Heffernan5-Jan-07 5:58 
Greetings all. I'm writing a performance test harness for a system that uses the System.Collections.Generics.Dictionary to contain some rather large collections of things, and I'd like to pick a random entry from these dictionaries and do something with it. The key and values cannot be easily produced randomly, so my best bet is to randomize an int between 0 and dict.Count, and then pull the entry. Obviously this would work fine with a Hashtable, since it has an integer indexer.

But I can't find any way to kludge an int indexer into a Dictionary that isn't a performance pig (which kind of distorts my performance test results). For example, my current (Uggh) code does this:

dictKeyType[] dictKeys = new dictKeyType[dict.Count];<br />
dict.Keys.CopyTo(dictKeys, 0);<br />
<br />
int idx = GetRandomInt(dictKeys.Length - 1);<br />
dictKeyType randomKey = dictKeys[idx];<br />


but obviously for large amounts of data, the array copy is going to distort both time and memory use. The distortion in memory use can be avoided by doing a foreach loop through the keys while decrementing the randomInt and then taking the value when you hit zero... but man, wouldn't it be better to just have an int indexer on the Dictionary (or Keys)?

Anyone have an idea on this? Or have I just missed something immensely simple? Smile | :)


Mike
---------------------
www.opusedge.com

AnswerRe: Getting a random entry from a Generic Dictionary Pin
Ravi Bhavnani5-Jan-07 6:41
professionalRavi Bhavnani5-Jan-07 6:41 
GeneralRe: Getting a random entry from a Generic Dictionary Pin
Mike Heffernan5-Jan-07 9:03
Mike Heffernan5-Jan-07 9:03 
GeneralRe: Getting a random entry from a Generic Dictionary Pin
Ravi Bhavnani5-Jan-07 9:28
professionalRavi Bhavnani5-Jan-07 9:28 
AnswerRe: Getting a random entry from a Generic Dictionary Pin
Luc Pattyn5-Jan-07 7:22
sitebuilderLuc Pattyn5-Jan-07 7:22 
GeneralRe: Getting a random entry from a Generic Dictionary Pin
Mike Heffernan5-Jan-07 9:05
Mike Heffernan5-Jan-07 9:05 
QuestionHow to insert picture in RTB & hot to printing from Rich Text Box Pin
TrooperIronMan5-Jan-07 5:42
TrooperIronMan5-Jan-07 5:42 
AnswerRe: How to insert picture in RTB & hot to printing from Rich Text Box Pin
TrooperIronMan6-Jan-07 7:44
TrooperIronMan6-Jan-07 7:44 
GeneralRe: How to insert picture in RTB & hot to printing from Rich Text Box Pin
TrooperIronMan6-Jan-07 11:19
TrooperIronMan6-Jan-07 11:19 

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.