Click here to Skip to main content
15,910,471 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.

 
GeneralUntested Backups with IonicZip Pin
kmoorevs16hrs 26mins ago
kmoorevs16hrs 26mins ago 
GeneralLooking at the very topmost line ... Pin
trønderen1-Jun-24 11:21
trønderen1-Jun-24 11:21 
GeneralRe: Looking at the very topmost line ... Pin
Greg Utas1-Jun-24 16:42
professionalGreg Utas1-Jun-24 16:42 
GeneralRe: Looking at the very topmost line ... Pin
Daniel Pfeffer1-Jun-24 19:57
professionalDaniel Pfeffer1-Jun-24 19:57 
GeneralBlessed endian mismatches collide with progress Pin
honey the codewitch1-Jun-24 7:30
mvahoney the codewitch1-Jun-24 7:30 
GeneralRe: Blessed endian mismatches collide with progress Pin
Ron Anders1-Jun-24 8:26
Ron Anders1-Jun-24 8:26 
JokeRe: Blessed endian mismatches collide with progress Pin
PIEBALDconsult1-Jun-24 9:22
mvePIEBALDconsult1-Jun-24 9:22 
GeneralRe: Blessed endian mismatches collide with progress Pin
trønderen1-Jun-24 11:13
trønderen1-Jun-24 11:13 
GeneralRe: Blessed endian mismatches collide with progress Pin
honey the codewitch1-Jun-24 11:33
mvahoney the codewitch1-Jun-24 11:33 
GeneralRe: Blessed endian mismatches collide with progress Pin
trønderen1-Jun-24 12:39
trønderen1-Jun-24 12:39 
GeneralRe: Blessed endian mismatches collide with progress Pin
honey the codewitch1-Jun-24 12:47
mvahoney the codewitch1-Jun-24 12:47 
GeneralRe: Blessed endian mismatches collide with progress Pin
trønderen17hrs 24mins ago
trønderen17hrs 24mins ago 
GeneralRe: Blessed endian mismatches collide with progress Pin
honey the codewitch17hrs 22mins ago
mvahoney the codewitch17hrs 22mins ago 
GeneralRe: Blessed endian mismatches collide with progress Pin
11917640 Member 20hrs 16mins ago
11917640 Member 20hrs 16mins ago 
GeneralRe: Blessed endian mismatches collide with progress Pin
kalberts17hrs 22mins ago
kalberts17hrs 22mins ago 
GeneralRe: Blessed endian mismatches collide with progress Pin
11917640 Member 3hrs 46mins ago
11917640 Member 3hrs 46mins 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 

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.