© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
16 replies
Tim

❔ Static interface methods

I have several classes implementing my Codec interface like this:
public sealed class CodecByte : Codec<byte>
{
    public byte Decode(EncodedData data) => data.Buffer[0];

    public EncodedData Encode(byte data) => new EncodedData(new byte[] { data });
}
public sealed class CodecByte : Codec<byte>
{
    public byte Decode(EncodedData data) => data.Buffer[0];

    public EncodedData Encode(byte data) => new EncodedData(new byte[] { data });
}

Is there a better way to represent multiple actions (
Encode
Encode
and
Decode
Decode
) without using a class?

- If there would have been a single method, I would start using a delegate. But a delegate can't do multiple things
- This is essentially just logic, so having this in a class is a bit useless (and makes me want to turn this into a singleton because instances aren't necessary)

So basically looking to eliminate the redundancy of a class (because I only need 1 instance) here while having those 2 functions combined (with a delegate somehow?)
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Concern over inheritance with static interface methods
C#CC# / help
2y ago
❔ Static methods
C#CC# / help
3y ago
static private things(methods,fields...)
C#CC# / help
4y ago
Static Members of an Interface
C#CC# / help
7mo ago