Click here to Skip to main content
15,910,009 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralLooking at the very topmost line ... Pin
trønderen10hrs 55mins ago
trønderen10hrs 55mins ago 
GeneralRe: Looking at the very topmost line ... Pin
Greg Utas5hrs 34mins ago
professionalGreg Utas5hrs 34mins ago 
GeneralRe: Looking at the very topmost line ... Pin
Daniel Pfeffer2hrs 19mins ago
professionalDaniel Pfeffer2hrs 19mins ago 
GeneralBlessed endian mismatches collide with progress Pin
honey the codewitch14hrs 46mins ago
mvahoney the codewitch14hrs 46mins ago 
GeneralRe: Blessed endian mismatches collide with progress Pin
Ron Anders13hrs 50mins ago
Ron Anders13hrs 50mins ago 
JokeRe: Blessed endian mismatches collide with progress Pin
PIEBALDconsult12hrs 54mins ago
mvePIEBALDconsult12hrs 54mins ago 
GeneralRe: Blessed endian mismatches collide with progress Pin
trønderen11hrs 3mins ago
trønderen11hrs 3mins ago 
GeneralRe: Blessed endian mismatches collide with progress Pin
honey the codewitch10hrs 43mins ago
mvahoney the codewitch10hrs 43mins ago 
GeneralRe: Blessed endian mismatches collide with progress Pin
trønderen9hrs 37mins ago
trønderen9hrs 37mins ago 
GeneralRe: Blessed endian mismatches collide with progress Pin
honey the codewitch9hrs 29mins ago
mvahoney the codewitch9hrs 29mins ago 
Generalimplementing interface method, same signature, from two interfaces Pin
raddevus25-Apr-24 9:55
mvaraddevus25-Apr-24 9:55 
Here's a little test for you.

Does this code compile?
C#
public interface IStorage{
    int Save();
}

public interface IPersist{
    int Save();
}

public class SaveImplementor : IStorage, IPersist{
    public int Save(){
        return 1;
    }
}


I'm implementing two interfaces which contain the same virtual method signature.

Well, it seems a little odd to me.

Obviously, if you want the separate implementations you have to write them explicitly.

Like this:

C#
public class SaveImplementor : IStorage, IPersist{

    int IStorage.Save(){
        return 1;
    }

    int IPersist.Save(){
        return 2;
    }
}

IMPORTANT NOTE: Notice that in the first example you HAVE to include the public modifier on the method implementation.

HOWEVER, on the second example where you explicitly implement the Interface method you CANNOT include the public modifier.

I'm filing this one under weird.

But, I guess I accept it. I have to, or else the C# compiler doesn't accept me. Roll eyes | :rolleyes:

Answer - The first example does indeed compile.

EDIT

Oh, and after I posted that, I went back and new'd up a SaveImplementor() and then I couldn't figure out how to call either of those explicit methods.
Hmm... It's got me thinking now.

EDIT 2
Here's the simple example that explains the explicit implementation: Explicit Interface Implementation - C# Programming Guide - C# | Microsoft Learn[^] .

modified 25-Apr-24 16:36pm.

GeneralRe: implementing interface method, same signature, from two interfaces Pin
Jon McKee25-Apr-24 12:27
professionalJon McKee25-Apr-24 12:27 
GeneralRe: implementing interface method, same signature, from two interfaces Pin
Richard Deeming30-Apr-24 0:30
mveRichard Deeming30-Apr-24 0:30 
GeneralRe: implementing interface method, same signature, from two interfaces Pin
honey the codewitch2-May-24 13:49
mvahoney the codewitch2-May-24 13:49 
RantGiven enough eyeballs - a Sunday rant... Pin
Mircea Neacsu21-Apr-24 7:32
Mircea Neacsu21-Apr-24 7:32 
GeneralRe: Given enough eyeballs - a Sunday rant... Pin
Greg Utas21-Apr-24 8:10
professionalGreg Utas21-Apr-24 8:10 
GeneralRe: Given enough eyeballs - a Sunday rant... Pin
Mircea Neacsu21-Apr-24 8:18
Mircea Neacsu21-Apr-24 8:18 
GeneralRe: Given enough eyeballs - a Sunday rant... Pin
Greg Utas21-Apr-24 10:11
professionalGreg Utas21-Apr-24 10:11 
GeneralRe: Given enough eyeballs - a Sunday rant... Pin
charlieg21-May-24 23:52
charlieg21-May-24 23:52 
GeneralRe: Given enough eyeballs - a Sunday rant... Pin
trønderen22-May-24 2:45
trønderen22-May-24 2:45 
GeneralRe: Given enough eyeballs - a Sunday rant... Pin
charlieg22-May-24 7:51
charlieg22-May-24 7:51 
JokeRe: Given enough eyeballs - a Sunday rant... Pin
Chris Maunder22-May-24 8:00
cofounderChris Maunder22-May-24 8:00 
GeneralRe: Given enough eyeballs - a Sunday rant... Pin
Mircea Neacsu22-May-24 8:09
Mircea Neacsu22-May-24 8:09 
GeneralCountry code Pin
PIEBALDconsult16-Apr-24 17:07
mvePIEBALDconsult16-Apr-24 17:07 
GeneralRe: Country code Pin
Peter_in_278016-Apr-24 17:50
professionalPeter_in_278016-Apr-24 17:50 

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.