Click here to Skip to main content
15,915,093 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using .NET 2.0 from VS2003 editor ? Pin
N a v a n e e t h18-Nov-07 23:23
N a v a n e e t h18-Nov-07 23:23 
GeneralRe: Using .NET 2.0 from VS2003 editor ? Pin
originSH18-Nov-07 23:55
originSH18-Nov-07 23:55 
GeneralRe: Using .NET 2.0 from VS2003 editor ? Pin
Daniel Grunwald19-Nov-07 1:49
Daniel Grunwald19-Nov-07 1:49 
QuestionDictionary where the key is a combination of values? Pin
Rune Baess18-Nov-07 21:48
Rune Baess18-Nov-07 21:48 
AnswerRe: Dictionary where the key is a combination of values? Pin
Martin#18-Nov-07 21:56
Martin#18-Nov-07 21:56 
GeneralRe: Dictionary where the key is a combination of values? Pin
Rune Baess19-Nov-07 0:06
Rune Baess19-Nov-07 0:06 
AnswerRe: Dictionary where the key is a combination of values? Pin
Ennis Ray Lynch, Jr.19-Nov-07 4:08
Ennis Ray Lynch, Jr.19-Nov-07 4:08 
GeneralRe: Dictionary where the key is a combination of values? Pin
Rune Baess19-Nov-07 5:36
Rune Baess19-Nov-07 5:36 
Sounds like the way to go ...

This performs quite well, but it still does not solve having n-number of values as a key, only two this time ...

<br />
void Main()<br />
{<br />
    Dictionary<Key<int, string>, MyClass> dictionary = new Dictionary<Key<int, string>, MyClass>();<br />
    <br />
    MyClass obj = new MyClass();<br />
    // set propeties<br />
    dictionary.Add(obj.GetKey(), obj);<br />
}<br />
<br />
<br />
<br />
<br />
public struct Key<T1, T2> : IEquatable<Key<T1, T2>><br />
{<br />
	public Key(T1 keyValue1, T2 keyValue2)<br />
	{<br />
		_keyValue1 = keyValue1;<br />
		_keyValue2 = keyValue2;<br />
	}<br />
<br />
	private T1 _keyValue1;<br />
	private T2 _keyValue2;<br />
<br />
	public override int GetHashCode()<br />
	{<br />
		return _keyValue1.GetHashCode() ^ _keyValue2.GetHashCode();<br />
	}<br />
<br />
	public override bool Equals(object other)<br />
	{<br />
		return this.GetHashCode().Equals(other.GetHashCode());<br />
	}<br />
<br />
}<br />
<br />
<br />
<br />
public sealed class MyClass<br />
{<br />
<br />
	private int _Key1;<br />
	private string _Key2;<br />
	private string _Value1;<br />
<br />
	public int Key1<br />
	{<br />
		get { return _Key1; }<br />
		set { _Key1 = value; }<br />
	}<br />
<br />
	public string Key2<br />
	{<br />
		get { return _Key2; }<br />
		set { _Key2 = value; }<br />
	}<br />
<br />
	public string Value1<br />
	{<br />
		get { return _Value1; }<br />
		set { _Value1 = value; }<br />
	}<br />
<br />
	public Key<int, string> GetKey()<br />
	{<br />
		return new Key<int, string>(this.Key1, this.Key2);<br />
	}<br />
<br />
}<br />
<br />

AnswerRe: Dictionary where the key is a combination of values? Pin
PIEBALDconsult19-Nov-07 13:47
mvePIEBALDconsult19-Nov-07 13:47 
GeneralRe: Dictionary where the key is a combination of values? Pin
Rune Baess19-Nov-07 20:31
Rune Baess19-Nov-07 20:31 
GeneralRe: Dictionary where the key is a combination of values? Pin
PIEBALDconsult20-Nov-07 5:54
mvePIEBALDconsult20-Nov-07 5:54 
AnswerRe: Dictionary where the key is a combination of values? Pin
PIEBALDconsult20-Nov-07 17:44
mvePIEBALDconsult20-Nov-07 17:44 
GeneralRe: Dictionary where the key is a combination of values? Pin
Rune Baess21-Nov-07 10:15
Rune Baess21-Nov-07 10:15 
GeneralRe: Dictionary where the key is a combination of values? Pin
PIEBALDconsult21-Nov-07 12:11
mvePIEBALDconsult21-Nov-07 12:11 
GeneralRe: Dictionary where the key is a combination of values? Pin
PIEBALDconsult23-Nov-07 7:25
mvePIEBALDconsult23-Nov-07 7:25 
QuestionHow do I "test" an Exception type? Pin
JoeRip18-Nov-07 21:37
JoeRip18-Nov-07 21:37 
AnswerRe: How do I "test" an Exception type? Pin
laserbaronen18-Nov-07 21:39
laserbaronen18-Nov-07 21:39 
GeneralRe: How do I "test" an Exception type? Pin
JoeRip18-Nov-07 21:42
JoeRip18-Nov-07 21:42 
GeneralRe: How do I &amp;quot;test&amp;quot; an Exception type? Pin
JoeRip18-Nov-07 21:50
JoeRip18-Nov-07 21:50 
GeneralRe: How do I "test" an Exception type? Pin
Martin#18-Nov-07 21:53
Martin#18-Nov-07 21:53 
GeneralRe: How do I "test" an Exception type? Pin
JoeRip18-Nov-07 22:01
JoeRip18-Nov-07 22:01 
GeneralRe: How do I "test" an Exception type? Pin
Martin#18-Nov-07 22:06
Martin#18-Nov-07 22:06 
GeneralRe: How do I "test" an Exception type? Pin
PIEBALDconsult19-Nov-07 4:23
mvePIEBALDconsult19-Nov-07 4:23 
GeneralRe: How do I &amp;quot;test&amp;quot; an Exception type? Pin
JoeRip18-Nov-07 21:58
JoeRip18-Nov-07 21:58 
GeneralRe: How do I &amp;quot;test&amp;quot; an Exception type? Pin
J4amieC18-Nov-07 22:33
J4amieC18-Nov-07 22:33 

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.