Click here to Skip to main content
15,893,814 members
Home / Discussions / C#
   

C#

 
QuestionHow to create netmodule in Visual Studio.net Pin
jinzhecheng17-Jan-06 8:19
jinzhecheng17-Jan-06 8:19 
AnswerRe: How to create netmodule in Visual Studio.net Pin
Dave Kreskowiak17-Jan-06 9:49
mveDave Kreskowiak17-Jan-06 9:49 
QuestionSession problem Pin
Snowjim17-Jan-06 8:05
Snowjim17-Jan-06 8:05 
AnswerRe: Session problem Pin
siva pinnaka17-Jan-06 10:27
siva pinnaka17-Jan-06 10:27 
AnswerRe: Session problem Pin
Guffa17-Jan-06 10:29
Guffa17-Jan-06 10:29 
GeneralRe: Session problem Pin
Snowjim18-Jan-06 9:03
Snowjim18-Jan-06 9:03 
AnswerRe: Session problem Pin
Snowjim18-Jan-06 10:10
Snowjim18-Jan-06 10:10 
QuestionHashtable problem... Pin
Chris Richner17-Jan-06 6:51
Chris Richner17-Jan-06 6:51 
Current issue is making me crazy at the moment, there must be something I missed, 'cause it's not working as expected...

I like to access a hash table key either by it's name or a class instance. To achieve this I create a new class (HashKey) which internally has a string called _name. When the hashtable calls HashKey.GetHashCode() it returns the HashCode of the internal wrapped string _name. Should be pretty much the same like I would use a literal string value key directly, right?
so it must the be same if I add my value by a string key

C#
HashTable myHashTable = new HashTable();
myHashTable.Add("keyName", 4);

or I add my value by a string key wrapped in HashKey class.
C#
HashKey myHashKey = new HashKey("keyName");
myHashTable.Add(myHashKey, 4);


Now I should/wanna be able to read the value by literal string or by the HashKey instance.

C#
object value = myHashTable["keyName"];
//
value = myHashTable[myHashKey];


This doesn't work, but WHY?

Here is the implemenation of HashKey class, which wraps the string and overrides GetHashCode and Equals methods.
C#
public class HashKey
{
	private string _name;
	
	public HashKey(string name)
	{
		_name = name;
	}
	public override string ToString()
	{
		return _name;
	}

	public override int GetHashCode()
	{
		return  _name.GetHashCode();
	}
	public override bool Equals(object obj)
	{
		return _name.Equals (obj);
	}


}

AnswerRe: Hashtable problem... Pin
User 665817-Jan-06 7:39
User 665817-Jan-06 7:39 
QuestionRe: Hashtable problem... Pin
Chris Richner17-Jan-06 7:54
Chris Richner17-Jan-06 7:54 
AnswerRe: Hashtable problem... Pin
User 665817-Jan-06 8:00
User 665817-Jan-06 8:00 
GeneralRe: Hashtable problem... Pin
Chris Richner17-Jan-06 23:12
Chris Richner17-Jan-06 23:12 
GeneralRe: Hashtable problem... Pin
User 665818-Jan-06 2:14
User 665818-Jan-06 2:14 
GeneralRe: Hashtable problem... Pin
Chris Richner18-Jan-06 5:46
Chris Richner18-Jan-06 5:46 
Questioncustom attribute serialization in C# Pin
softplanner17-Jan-06 6:49
softplanner17-Jan-06 6:49 
QuestionSerial Port Status Reader Pin
kinder202317-Jan-06 6:33
kinder202317-Jan-06 6:33 
AnswerRe: Serial Port Status Reader Pin
Dave Kreskowiak17-Jan-06 8:16
mveDave Kreskowiak17-Jan-06 8:16 
Questionsession management using sql server Pin
mevir17-Jan-06 6:10
mevir17-Jan-06 6:10 
QuestionUpdate the dataset into the original database Pin
Sasuko17-Jan-06 5:05
Sasuko17-Jan-06 5:05 
AnswerRe: Update the dataset into the original database Pin
Christian Graus17-Jan-06 9:21
protectorChristian Graus17-Jan-06 9:21 
GeneralRe: Update the dataset into the original database Pin
Sasuko17-Jan-06 9:28
Sasuko17-Jan-06 9:28 
GeneralRe: Update the dataset into the original database Pin
Christian Graus17-Jan-06 9:37
protectorChristian Graus17-Jan-06 9:37 
GeneralRe: Update the dataset into the original database Pin
Sasuko17-Jan-06 9:53
Sasuko17-Jan-06 9:53 
GeneralRe: Update the dataset into the original database Pin
Christian Graus17-Jan-06 9:56
protectorChristian Graus17-Jan-06 9:56 
GeneralRe: Update the dataset into the original database Pin
Sasuko17-Jan-06 10:19
Sasuko17-Jan-06 10: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.