Click here to Skip to main content
15,899,314 members
Home / Discussions / C#
   

C#

 
GeneralRe: simple messagebox Pin
Ista9-Aug-03 9:53
Ista9-Aug-03 9:53 
GeneralBarcode reader and Receipt printer Pin
ChiYung8-Aug-03 19:53
ChiYung8-Aug-03 19:53 
GeneralRe: Barcode reader and Receipt printer Pin
AdrianT9-Aug-03 1:12
AdrianT9-Aug-03 1:12 
GeneralRe: Barcode reader and Receipt printer Pin
ChiYung9-Aug-03 8:07
ChiYung9-Aug-03 8:07 
GeneralRe: Barcode reader and Receipt printer Pin
Ista9-Aug-03 12:15
Ista9-Aug-03 12:15 
Generalinterface method access modifier Pin
devvvy8-Aug-03 17:13
devvvy8-Aug-03 17:13 
GeneralRe: interface method access modifier Pin
Nish Nishant8-Aug-03 17:28
sitebuilderNish Nishant8-Aug-03 17:28 
Generalfound it! Pin
devvvy8-Aug-03 21:10
devvvy8-Aug-03 21:10 
You can append access modifer when you implement it in a class, PROVIDED that the interface is not the base interface of another interface that the class implements.

Using example below, IAccMaintenance is the base interface of IAccManager:

interface IAccMaintenance
{
int EditAccProfile(...); //DO NOT append access modifer to this method when you implement it.
}

interface IAccManager : IAccMaintenance
{
...
}

Now, when you implement it in a class:
class SiteManager : IAccManager
{
public int IAccManager.CreateAcc(...) {...} //That's OK. You can use access modifier here.
public int EditAccProfile(...) {...} //ERROR: You can't use access modifier - the method comes from an interface that's not directly inherited. But why would .NET team design it this way???

...
}

***********************************************************************
In case you want to just compile the code and see...
using System;

namespace try_interface2
{
public interface IAccMaintenance
{
int EditAccProfile(int accID);
}

public interface IOldAccMaintenance
{
int EditAccProfile(int accID);
}

public interface IAccManager : IAccMaintenance, IOldAccMaintenance
{
int CreateAcc(string accType, int accID);
int DestroyAcc(int accID);

int numAccount
{
get;
set;
}
}

interface IConnManager
{
int Connect(string Destination, int connID);
int Disconn(int connID);
}


class CSiteManager : IAccManager, IConnManager
{
protected int m_numAccount;

//(1) Implementing IAccManager interface:
public int CreateAcc(string accType, int accID)
{
Console.WriteLine("CreateAcc... account type: {0}, account ID: {1}", accType, accID.ToString());
return 1;
}

public int DestroyAcc(int accID)
{
Console.WriteLine("Destroy Acc... account ID: {0}", accID.ToString());
return 1;
}

public int numAccount
{
get{ return m_numAccount; }
set{ m_numAccount=value; }
}

int IAccMaintenance.EditAccProfile(int accID)
{
int err=0;
Console.WriteLine("edit acc profile ver 0. accID: {0}", accID);
return err;
}

int IOldAccMaintenance.EditAccProfile(int accID)
{
int err=0;
Console.WriteLine("edit acc profile ver 0. accID: {0}", accID);
return err;
}



//(2) Implementing IConnManager interface (Default method access modifier: private):
int IConnManager.Connect(string Destination, int connID)
{
int err=0;
Console.WriteLine("Connect... destination: {0} connID: {1}", Destination, connID);
return err;
}

int IConnManager.Disconn(int connID)
{
int err=0;
Console.WriteLine("Disconn... connID: {0}", connID);
return err;
}

}


///
/// Summary description for Class1.
///

class AppClass
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
CSiteManager siteManager = new CSiteManager();
siteManager.CreateAcc("developer_premimum", 731);
siteManager.DestroyAcc(423);
siteManager.numAccount = 14302;
Console.WriteLine("Number of registered accounts: {0}", siteManager.numAccount);

}
}
}


norm
GeneralRe: interface method access modifier Pin
Jim Stewart8-Aug-03 19:37
Jim Stewart8-Aug-03 19:37 
GeneralRe: interface method access modifier Pin
devvvy8-Aug-03 19:56
devvvy8-Aug-03 19:56 
GeneralRe: interface method access modifier Pin
Bo Hunter8-Aug-03 19:38
Bo Hunter8-Aug-03 19:38 
Generalseparate method declaration and implementation Pin
devvvy8-Aug-03 16:42
devvvy8-Aug-03 16:42 
GeneralRe: separate method declaration and implementation Pin
Nish Nishant8-Aug-03 16:58
sitebuilderNish Nishant8-Aug-03 16:58 
GeneralRe: separate method declaration and implementation Pin
devvvy8-Aug-03 17:17
devvvy8-Aug-03 17:17 
GeneralRe: separate method declaration and implementation Pin
Nish Nishant8-Aug-03 17:23
sitebuilderNish Nishant8-Aug-03 17:23 
GeneralRe: separate method declaration and implementation Pin
devvvy8-Aug-03 17:52
devvvy8-Aug-03 17:52 
GeneralRe: separate method declaration and implementation Pin
J. Dunlap8-Aug-03 18:08
J. Dunlap8-Aug-03 18:08 
GeneralRe: separate method declaration and implementation Pin
devvvy8-Aug-03 19:59
devvvy8-Aug-03 19:59 
GeneralRe: separate method declaration and implementation Pin
J. Dunlap8-Aug-03 20:11
J. Dunlap8-Aug-03 20:11 
GeneralRe: separate method declaration and implementation Pin
James T. Johnson9-Aug-03 0:02
James T. Johnson9-Aug-03 0:02 
GeneralRe: separate method declaration and implementation Pin
Jim Stewart8-Aug-03 19:40
Jim Stewart8-Aug-03 19:40 
GeneralRemoving duplicates in an array Pin
mikemilano8-Aug-03 10:21
mikemilano8-Aug-03 10:21 
GeneralRe: Removing duplicates in an array Pin
Krishnan111119778-Aug-03 13:53
Krishnan111119778-Aug-03 13:53 
GeneralRe: Removing duplicates in an array Pin
James T. Johnson8-Aug-03 14:30
James T. Johnson8-Aug-03 14:30 
General"Removing Events" and -= Pin
flipdoubt8-Aug-03 9:19
flipdoubt8-Aug-03 9: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.