Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 119395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:38:47+00:00 2026-05-11T03:38:47+00:00

The general rule is that I want to say, T has a method with

  • 0

The general rule is that I want to say, ‘T has a method with a String parameter which will return List.’ Put verbosely, we might call the interface ICanCreateListOfObjectsFromString. A possible application might be search.

It feels like it’d be nice to have a static method in my interface, but I know that’s not allowed in C#. What is another approach to specify this kind of contract implementation on a class?

Edit: I would like to have the following code:

public interface ISearch {     static List<T> Search<T>(String s); }  public class MyObject : ISearch {     List<MyObject> Search(string s) {         //...     } }  public List<T> DoFooSearch<T:ISearch> () {         return T.Search('Foo'); }  public List<T> DoBarSearch<T:ISearch> () {         return T.Search('Bar'); } 

You can probably see why this code won’t compile, but it expresses the spirit of what I’d like to achieve. I hope this clarifies my intention a bit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:38:47+00:00Added an answer on May 11, 2026 at 3:38 am

    Sounds like you’re trying to implement a Mixin… Something of that sort exists in C# 3.0, and they are named ‘Extension Methods’.

    What do allow you to do? Well, they allow you to create functions that work in types that you specify, and ‘add’ methods to them. Since that type can be an interface, this lets you define concrete functions for an interface.

    Admittedly, these functions aren’t part of the interface code itself, but they also aren’t part of any of the implementation of the interface. So it’s a ‘glass half full’ scenario.

    (A brief search led me to Implementing Mixins with C# Extension Methods.)

    Alternatively: if you don’t require multiple inheritance for the classes that implement your interface, you can use abstract classes instead of interfaces, and implement concrete functions directly in them. But then again, that means you give up on inheriting from anything but that class (and implementing other interfaces.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a general rule that can be used to determine this? E.g: int
I'm well aware that the general rule of thumb is you should only import
There is a general rule of OO design that you should model is-a relationships
In programming there is a general rule introduced by Kernighan & Ritchie saying that
I wonder the general rule to use regular expression in if clause in bash?
As a general rule, are Java compilers localised? Are the compilers capable of emitting
I was told by an experienced programmer(spoj,codechef,topcoder etc ) than as a general rule
General javascript question here, which would also be good to know how(if possible) to
general question is i like to build logger class that writes to single log
Let's say I have a list, with an arbitrary number of indentation levels, like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.