Click here to Skip to main content
15,888,984 members
Home / Discussions / C#
   

C#

 
GeneralFileSize Pin
kavehdr8-Nov-02 12:08
kavehdr8-Nov-02 12:08 
GeneralRe: FileSize Pin
ian mariano8-Nov-02 20:03
ian mariano8-Nov-02 20:03 
GeneralC# determinism Pin
AaronStibich8-Nov-02 12:03
AaronStibich8-Nov-02 12:03 
QuestionAaarrrgggghhh what have I done??? Pin
LongRange.Shooter8-Nov-02 9:24
LongRange.Shooter8-Nov-02 9:24 
AnswerRe: Aaarrrgggghhh what have I done??? Pin
LongRange.Shooter8-Nov-02 9:41
LongRange.Shooter8-Nov-02 9:41 
GeneralHashtable Pin
afronaut8-Nov-02 6:57
afronaut8-Nov-02 6:57 
GeneralRe: Hashtable Pin
perlmunger8-Nov-02 7:19
perlmunger8-Nov-02 7:19 
GeneralRe: Hashtable Pin
afronaut8-Nov-02 8:51
afronaut8-Nov-02 8:51 
Thanks Matt -

I needed to have a hashtable of months of the year:
"January","1"
"February","2"
...
and be able to get a month based on a numeric index OR an index based on a month string.
I thought it would be easy with a Hashtable but you're right - it doesn't support lookups by value assuming you could have multiple 'values' with different keys. But there are a lot of cases like this where I know there is a one to one mapping of name/value pairs. Items that are always used in association and are unique.

I used a simple array and wrote a finder method that looked like this:

<br />
string[] months = {"Jan","Feb","Mar",...}<br />
<br />
		private int GetMonthIndex(string mo){<br />
			for(int i=0;i<mos.Length;i++){<br />
				if(mos[i]==mo)return i+1;<br />
			}<br />
			return -1; // <-- if it doesn't pan out...<br />
		}<br />


Incidentally I asked my perl jedi master and he must have been laughing when he wrote this:
<br />
$hash{'David'} = 'C#';<br />
$hash{'Chris'} = 'Perl';<br />
@keys = grep { $hash{$_} eq 'Perl' } keys %hash;  #perl is s1ck<br />


In the end, while I didn't change my use of a simple array and a brutally slow sequential search, I wrote this for future reference:

<br />
		public static string GrepHashForKey(Hashtable ha, string search){<br />
			foreach(object o in ha.Keys){<br />
				if(ha[o].ToString().Equals(search))<br />
					return o.ToString();<br />
			}<br />
			return "";<br />
		}<br />


*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
GeneralRe: Hashtable Pin
perlmunger8-Nov-02 9:22
perlmunger8-Nov-02 9:22 
GeneralRe: Hashtable Pin
afronaut8-Nov-02 9:52
afronaut8-Nov-02 9:52 
GeneralRe: Hashtable Pin
leppie8-Nov-02 12:48
leppie8-Nov-02 12:48 
GeneralRe: Hashtable Pin
John Fisher8-Nov-02 11:05
John Fisher8-Nov-02 11:05 
QuestionCan someone verify these assumptions on dialog boxes? Pin
LongRange.Shooter8-Nov-02 6:35
LongRange.Shooter8-Nov-02 6:35 
AnswerRe: Can someone verify these assumptions on dialog boxes? Pin
Daaron8-Nov-02 6:44
Daaron8-Nov-02 6:44 
GeneralRe: Can someone verify these assumptions on dialog boxes? Pin
LongRange.Shooter8-Nov-02 6:48
LongRange.Shooter8-Nov-02 6:48 
AnswerRe: Can someone verify these assumptions on dialog boxes? Pin
Richard Deeming8-Nov-02 6:53
mveRichard Deeming8-Nov-02 6:53 
AnswerRe: Can someone verify these assumptions on dialog boxes? Pin
James T. Johnson8-Nov-02 7:07
James T. Johnson8-Nov-02 7:07 
GeneralTransparency Pin
MrEyes8-Nov-02 6:14
MrEyes8-Nov-02 6:14 
GeneralRe: Transparency Pin
Paul Watson8-Nov-02 6:45
sitebuilderPaul Watson8-Nov-02 6:45 
GeneralRe: Transparency Pin
Andrew Lewis8-Nov-02 8:50
Andrew Lewis8-Nov-02 8:50 
GeneralRe: Transparency Pin
Paul Watson9-Nov-02 5:38
sitebuilderPaul Watson9-Nov-02 5:38 
Generalwin2k can show transparency too ... Pin
Karavaev Denis9-Nov-02 5:33
Karavaev Denis9-Nov-02 5:33 
GeneralRe: win2k can show transparency too ... Pin
Paul Watson9-Nov-02 5:38
sitebuilderPaul Watson9-Nov-02 5:38 
GeneralRe: Transparency Pin
MrEyes11-Nov-02 1:52
MrEyes11-Nov-02 1:52 
GeneralRe: Transparency Pin
Paul Watson11-Nov-02 2:11
sitebuilderPaul Watson11-Nov-02 2:11 

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.