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

C#

 
GeneralRe: Sys-wide keyboard hook Pin
Luis Alonso Ramos24-Jul-02 21:02
Luis Alonso Ramos24-Jul-02 21:02 
GeneralRe: Sys-wide keyboard hook Pin
Alex Korchemniy25-Jul-02 7:20
Alex Korchemniy25-Jul-02 7:20 
GeneralRe: Sys-wide keyboard hook Pin
Luis Alonso Ramos25-Jul-02 10:57
Luis Alonso Ramos25-Jul-02 10:57 
GeneralCopy Constructor Pin
Johnny Zee24-Jul-02 16:54
sussJohnny Zee24-Jul-02 16:54 
GeneralRe: Copy Constructor Pin
James T. Johnson24-Jul-02 18:08
James T. Johnson24-Jul-02 18:08 
GeneralRe: Copy Constructor Pin
Johnny Zee25-Jul-02 2:27
sussJohnny Zee25-Jul-02 2:27 
GeneralRe: Copy Constructor Pin
albean28-Jul-02 14:22
albean28-Jul-02 14:22 
GeneralRe: Copy Constructor Pin
James T. Johnson28-Jul-02 16:01
James T. Johnson28-Jul-02 16:01 
Its not a dumb question at all because the answer isn't obvious.

In the Foo class there are two different implementations of Clone(), one which is a member of the class and the other is Foo's implementation of ICloneable.

Interfaces in C# (and .NET) require that their members be public; so when I specifically implemented the Clone method as Foo's implementation of ICloneable I didn't need to specify the public access modifier.

In C# there are two different ways to implement an interface.

The first method is by adding a public member for each item in the interface you are implementing. Most people probably use this technique to implement an interface.

interface IBar
{
  object Bar();
}
 
class Foo : IBar
{
  ....
  
  public object Bar()
  {
     ....
  }
}
The second method is to specify in the member's signature what interface it is implementing.

class Baz : IBar
{
  ...
 
  object IBar.Bar()
  {
    ....
  }
}
Unlike the first method the only way to use this member is cast the object to the interface (IBar ib = (IBar) myBaz;). Now you can use the member as if it were any other interface.

This also gives an advantage for the users of your class. You can provide two different implementations of a member: one to be used when dealing with the interface, the other to be used when dealing with the class itself.

Most of the collections in the .NET class library do this to provide a strongly-typed collection while also implementing the generic interfaces that provide a standard way of using a collection.

Hope that answers your question

James
"Java is free - and worth every penny." - Christian Graus
GeneralConfigurationSettings Pin
Steve Severance24-Jul-02 13:12
Steve Severance24-Jul-02 13:12 
GeneralRe: ConfigurationSettings Pin
James T. Johnson24-Jul-02 16:18
James T. Johnson24-Jul-02 16:18 
GeneralRe: ConfigurationSettings Pin
jparsons25-Jul-02 2:45
jparsons25-Jul-02 2:45 
GeneralRe: ConfigurationSettings Pin
James T. Johnson25-Jul-02 2:50
James T. Johnson25-Jul-02 2:50 
GeneralNamespace Hell Pin
stephen woolhead24-Jul-02 13:12
stephen woolhead24-Jul-02 13:12 
GeneralRe: Namespace Hell Pin
James T. Johnson24-Jul-02 16:08
James T. Johnson24-Jul-02 16:08 
GeneralRe: Namespace Hell Pin
stephen woolhead24-Jul-02 22:13
stephen woolhead24-Jul-02 22:13 
GeneralRe: Namespace Hell Pin
James T. Johnson25-Jul-02 0:16
James T. Johnson25-Jul-02 0:16 
GeneralRe: Namespace Hell Pin
jparsons25-Jul-02 2:49
jparsons25-Jul-02 2:49 
GeneralProblems with ListView and columns Pin
Luis Alonso Ramos24-Jul-02 9:53
Luis Alonso Ramos24-Jul-02 9:53 
GeneralRe: Problems with ListView and columns Pin
leppie24-Jul-02 20:44
leppie24-Jul-02 20:44 
GeneralRe: Problems with ListView and columns Pin
Luis Alonso Ramos24-Jul-02 21:01
Luis Alonso Ramos24-Jul-02 21:01 
GeneralRe: Problems with ListView and columns Pin
leppie25-Jul-02 3:28
leppie25-Jul-02 3:28 
GeneralRe: Problems with ListView and columns Pin
Luis Alonso Ramos25-Jul-02 6:49
Luis Alonso Ramos25-Jul-02 6:49 
GeneralRe: Problems with ListView and columns Pin
leppie25-Jul-02 7:29
leppie25-Jul-02 7:29 
GeneralRe: Problems with ListView and columns Pin
Luis Alonso Ramos25-Jul-02 11:04
Luis Alonso Ramos25-Jul-02 11:04 
GeneralRe: Problems with ListView and columns (finally fixed) Pin
Luis Alonso Ramos12-Aug-02 19:36
Luis Alonso Ramos12-Aug-02 19:36 

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.