Click here to Skip to main content
15,894,405 members
Home / Discussions / C#
   

C#

 
Generalremote ip Pin
Pyro Joe23-Nov-04 15:41
Pyro Joe23-Nov-04 15:41 
GeneralRe: remote ip Pin
Stefan Troschuetz23-Nov-04 22:48
Stefan Troschuetz23-Nov-04 22:48 
Questioncan I assign custom shortcuts to MenuItem.ShortCut? Pin
Anonymous23-Nov-04 14:06
Anonymous23-Nov-04 14:06 
AnswerRe: can I assign custom shortcuts to MenuItem.ShortCut? Pin
benjymous23-Nov-04 22:08
benjymous23-Nov-04 22:08 
GeneralRe: can I assign custom shortcuts to MenuItem.ShortCut? Pin
Heath Stewart24-Nov-04 5:53
protectorHeath Stewart24-Nov-04 5:53 
AnswerRe: can I assign custom shortcuts to MenuItem.ShortCut? Pin
Heath Stewart24-Nov-04 5:45
protectorHeath Stewart24-Nov-04 5:45 
QuestionWhat would the c# equivalent of make_pair be Pin
PaleyX23-Nov-04 11:13
PaleyX23-Nov-04 11:13 
AnswerRe: What would the c# equivalent of make_pair be Pin
Heath Stewart23-Nov-04 13:24
protectorHeath Stewart23-Nov-04 13:24 
A Hashtable stores key/values pairs that are both objects, meaning that you can store anything (since every Type in .NET extends System.Object). This means that you can store, for example, a class (best to use reference types to avoid boxing and unboxing performance penalties) with a couple of properties like so:
public class Person
{
  string name, DateTime birthday;
  public string Name
  {
    get { return name; }
    set { if (value == null) throw new ArgumentNullException(); name = value; }
  }
  public DateTime Birthday
  {
    get { return birthday; }
    set { birthday = value; }
  }
}
Then create an IComparer implementation to compare whatever property or properties you want, or have your class implement IComparable so that the default Comparer can juse use your implementation (this option is often best when defining your own types as it works without implementing and using a separate Type).

If you read the documentation for the Hashtable, however, you'll notice that if you don't pass an IComparer to the constructor the default comparer it uses will use the Equals override. So, you could also override Object.Equals (which implies you should override Object.GetHashCode) and not pass a comparer, or implement IComparable on your class and pass Comparer.Default to the Hashtable constructor, or implement IComparer and pass your implementation to the Hashtable constructor. This will allow you to compare keys, not values, though. For that, enumerate the Hashtable.Values collection or enumerate (using the IDictionaryEnumerator) the entire Hashtable to compare values so that you have both the key and value.

As far as whether to override Equals or implement IComparable, you could do both.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: What would the c# equivalent of make_pair be Pin
PaleyX23-Nov-04 14:05
PaleyX23-Nov-04 14:05 
AnswerRe: What would the c# equivalent of make_pair be Pin
Nick Parker23-Nov-04 13:25
protectorNick Parker23-Nov-04 13:25 
GeneralRe: What would the c# equivalent of make_pair be Pin
leppie24-Nov-04 6:09
leppie24-Nov-04 6:09 
GeneralRe: What would the c# equivalent of make_pair be Pin
Nick Parker24-Nov-04 7:23
protectorNick Parker24-Nov-04 7:23 
GeneralDynamically generate a MS Word document using ASP.Net Pin
john kuruvila23-Nov-04 10:59
john kuruvila23-Nov-04 10:59 
GeneralRe: Dynamically generate a MS Word document using ASP.Net Pin
DavidNohejl23-Nov-04 11:34
DavidNohejl23-Nov-04 11:34 
GeneralRe: Dynamically generate a MS Word document using ASP.Net Pin
Heath Stewart23-Nov-04 13:03
protectorHeath Stewart23-Nov-04 13:03 
GeneralRe: Dynamically generate a MS Word document using ASP.Net Pin
DavidNohejl23-Nov-04 11:44
DavidNohejl23-Nov-04 11:44 
GeneralDynamically generate a MS Word document using ASP.Net Pin
john kuruvila23-Nov-04 10:56
john kuruvila23-Nov-04 10:56 
GeneralRe: Dynamically generate a MS Word document using ASP.Net Pin
Heath Stewart23-Nov-04 12:59
protectorHeath Stewart23-Nov-04 12:59 
GeneralRe: Dynamically generate a MS Word document using ASP.Net Pin
john kuruvila23-Nov-04 13:32
john kuruvila23-Nov-04 13:32 
GeneralCenter of screen Pin
AlexMartins23-Nov-04 10:16
AlexMartins23-Nov-04 10:16 
GeneralRe: Center of screen Pin
Luis Alonso Ramos23-Nov-04 10:38
Luis Alonso Ramos23-Nov-04 10:38 
GeneralRe: Center of screen Pin
Daniel Turini24-Nov-04 1:17
Daniel Turini24-Nov-04 1:17 
QuestionBenefits of SqlTypes? Pin
sixefftee23-Nov-04 9:51
sixefftee23-Nov-04 9:51 
AnswerRe: Benefits of SqlTypes? Pin
Heath Stewart23-Nov-04 12:48
protectorHeath Stewart23-Nov-04 12:48 
GeneralRe: Benefits of SqlTypes? Pin
Charlie Williams23-Nov-04 13:12
Charlie Williams23-Nov-04 13:12 

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.