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 8764253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:59:07+00:00 2026-06-13T15:59:07+00:00

I have a doubt, i’ve searched a lot about it and i haven’t found

  • 0

I have a doubt, i’ve searched a lot about it and i haven’t found nothing that can explain.

I can have a property referencing an interface inside my class, and make use of DI to fill these property. For example:

public interface ITest {
    void DoSomething();
}

public class Test {
    ITest _test;

    public Test(Itest _test)
    {
        this._test = test;
    }
}

The problem is, if I have an generic interface, and my class don’t make use of generics, when i create these property a compile error is raised

public interface ITest<T> {
    void DoSomething(T parameter);
}

public class Test {
    ITest<T> _test; //error (Type cant be found)

    public Test(Itest<T> _test)
    {
        this._test = test;
    }
}

Is this possible?

  • 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. Editorial Team
    Editorial Team
    2026-06-13T15:59:08+00:00Added an answer on June 13, 2026 at 3:59 pm

    Your Test class needs to be generic too – otherwise there’s no way of knowing what kind of ITest<T> the _test variable refers to. How would you know how to call _test.DoSomething()? The type parameter of Test doesn’t have to be T, of course:

    public class Test<TFoo> {
        ITest<TFoo> _test;
    
        public Test(ITest<TFoo> _test)
        {
            this._test = test;
        }
    }
    

    You’d then construct it as:

    ITest<string> x = ...;
    Test<string> test = new Test<string>(x);
    

    Type safety would stop you from writing:

    Test<int> test = new Test<int>(x);
    

    because you can’t construct a Test<int> from an ITest<string>.

    Alternatively, your Test class may only need to take one specific kind of ITest, and therefore not be generic at all:

    public class Test {
        ITest<Guid> _test;
    
        public Test(ITest<Guid> _test)
        {
            this._test = test;
        }
    }
    

    It all depends on what you’re trying to achieve.

    EDIT: As noted in comments, if your Test class doesn’t use any of the aspects of ITest<T> which rely on T, you might want to create a non-generic base interface:

    public interface ITest {
        void DoSomethingBland();
    }
    
    public interface ITest<T> : ITest {
        void DoSomethingSpecific(T foo);
    }
    

    Then you could make your class just depend on the non-generic ITest interface instead of ITest<T>.

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

Sidebar

Related Questions

i have doubt about how can i iterate into a group of div, my
I have a doubt that a static class can contain a private constructor.
I have a doubt about how I can check an URL like this: http://your.url/set_new_password.php?userid=564979&code=54c4a2767c2f485185ab72cdcf03ab59
I have a doubt about Model behavior in Spring MVC. I have a controller
I have doubt about this two pattern, like MVC and PAC, which is more
Have one Doubt In MVC Architecture we can able to pass data from Controller
i have a doubt that whether javascript expression is better or regularexpression is better.
I have doubt about the Row_DataBound and Row_Created events : What is the difference
I have doubt whether we can do the following or not. Suppose I have
I have doubt about data structure transformation from one form of array to another.

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.