Click here to Skip to main content
15,881,173 members
Home / Discussions / C#
   

C#

 
GeneralRe: project file associated with c# application on start Pin
OriginalGriff15-Jan-17 1:23
mveOriginalGriff15-Jan-17 1:23 
GeneralRe: project file associated with c# application on start Pin
Eddy Vluggen15-Jan-17 1:25
professionalEddy Vluggen15-Jan-17 1:25 
QuestionCan't understand implementation of interface Pin
Mc_Topaz14-Jan-17 3:07
Mc_Topaz14-Jan-17 3:07 
AnswerRe: Can't understand implementation of interface Pin
OriginalGriff14-Jan-17 3:48
mveOriginalGriff14-Jan-17 3:48 
PraiseRe: Can't understand implementation of interface Pin
Mc_Topaz14-Jan-17 4:35
Mc_Topaz14-Jan-17 4:35 
GeneralRe: Can't understand implementation of interface Pin
OriginalGriff14-Jan-17 4:46
mveOriginalGriff14-Jan-17 4:46 
SuggestionRe: Can't understand implementation of interface Pin
Richard Deeming16-Jan-17 2:18
mveRichard Deeming16-Jan-17 2:18 
AnswerRe: Can't understand implementation of interface Pin
BillWoodruff17-Jan-17 16:49
professionalBillWoodruff17-Jan-17 16:49 
Everything declared in an Interface, when you implement it in a class, must have the access modifier 'public. This "default" implementation syntax can be called implicit implementation.

The exception, which does confuse people, is the special case where you have a class that implements more than one Interface and identical names are used in each Interface, and you need to make it clear, for a duplicated name implementation, which Interface your implementation refers to.

So, when explicit implementation is used: no modifiers are allowed; and, the Interface name is followed by a dot, and the declaration.

The examples here should make this clear: [^].

If you are one of those curious persons who dares ask why you can't have access modifiers in Interfaces, and/or why you can't use other modifiers than 'public in your implementation of Interfaces; you may wish to read this thread: [^].

Suppose your class implements one Interface, and you make every implementation explicit:
public interface IStuff
{
    void SPB(string a, DateTime d, string c);
    void P(decimal a, string r);
    void EPB();

    string Name { set; get; }
}

public class Test : IStuff
{
    void IStuff.SPB(string a, DateTime d, string c)
    {
        throw new NotImplementedException();
    }

    void IStuff.P(decimal a, string r)
    {
        throw new NotImplementedException();
    }

    void IStuff.EPB()
    {
        throw new NotImplementedException();
    }

    private string _name;

    string IStuff.Name
    {
        get { return _name; }
        set { _name = value; }
    }
}
When you create an instance of this class, none of its methods, and its one field, can be accessed from the instance: you'll have to cast the instance to the Interface:
// in some method, or class initializer, or eventhandler:
var test = new Test();

// causes error
// test.Name = "fail";

// okay
(test as IStuff).name = "wtf ?";

«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008


modified 18-Jan-17 2:48am.

QuestionDatatable to Excel Pin
Member 1294766512-Jan-17 11:41
Member 1294766512-Jan-17 11:41 
AnswerRe: Datatable to Excel Pin
Dave Kreskowiak12-Jan-17 11:50
mveDave Kreskowiak12-Jan-17 11:50 
GeneralRe: Datatable to Excel Pin
Chris Quinn13-Jan-17 3:53
Chris Quinn13-Jan-17 3:53 
GeneralRe: Datatable to Excel Pin
Dave Kreskowiak13-Jan-17 5:05
mveDave Kreskowiak13-Jan-17 5:05 
GeneralRe: Datatable to Excel Pin
Chris Quinn13-Jan-17 5:07
Chris Quinn13-Jan-17 5:07 
GeneralRe: Datatable to Excel Pin
theoldfool14-Jan-17 16:16
professionaltheoldfool14-Jan-17 16:16 
GeneralRe: Datatable to Excel Pin
Dave Kreskowiak14-Jan-17 16:45
mveDave Kreskowiak14-Jan-17 16:45 
GeneralRe: Datatable to Excel Pin
theoldfool15-Jan-17 2:21
professionaltheoldfool15-Jan-17 2:21 
AnswerRe: Datatable to Excel Pin
Brisingr Aerowing12-Jan-17 12:26
professionalBrisingr Aerowing12-Jan-17 12:26 
QuestionHow to Use Telerik Split button Pin
Member 1293879712-Jan-17 6:38
Member 1293879712-Jan-17 6:38 
AnswerRe: How to Use Telerik Split button Pin
NotPolitcallyCorrect12-Jan-17 8:03
NotPolitcallyCorrect12-Jan-17 8:03 
GeneralRe: How to Use Telerik Split button Pin
Member 1293879713-Jan-17 7:50
Member 1293879713-Jan-17 7:50 
GeneralRe: How to Use Telerik Split button Pin
NotPolitcallyCorrect13-Jan-17 8:25
NotPolitcallyCorrect13-Jan-17 8:25 
GeneralRe: How to Use Telerik Split button Pin
Graeme_Grant15-Jan-17 0:26
mvaGraeme_Grant15-Jan-17 0:26 
QuestionFingerprint and mysql database Pin
King_Eke11-Jan-17 11:26
King_Eke11-Jan-17 11:26 
AnswerRe: Fingerprint and mysql database Pin
Gerry Schmitz11-Jan-17 17:00
mveGerry Schmitz11-Jan-17 17:00 
AnswerRe: Fingerprint and mysql database Pin
Afzaal Ahmad Zeeshan11-Jan-17 23:17
professionalAfzaal Ahmad Zeeshan11-Jan-17 23:17 

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.