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

  • Home
  • SEARCH
  • 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 7754067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:12:52+00:00 2026-06-01T12:12:52+00:00

I have two classes: Superclass and derived Subclass:Superclass. I have a generic method: public

  • 0

I have two classes: Superclass and derived Subclass:Superclass. I have a generic method:

public void DoSmth<T>(T obj)
    where T : Superclass
{
    if(typeof(T).IsSubclassOf(typeof(Subclass))
    {
        DoSmth2<T>(obj);
    }
    //...
}

public void DoSmth2<T>(T obj)
    where T : Subclass
{ 
    //... 
}

As you see I want to call generic method for Subclass from generic method for Superclass. But compiler says that I can’t do that:

The type 'T' cannot be used as type parameter 
'T' in the generic type or method 'DoSmth2<T>(T)'. 
There is no implicit reference conversion from 'T' to 'Subclass'

I use .Net 3.5. I understand that I can’t do that just like I wrote above but is there any way to do that?

  • 1 1 Answer
  • 1 View
  • 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-01T12:12:54+00:00Added an answer on June 1, 2026 at 12:12 pm

    You can’t but you don’t have to either.

    public void DoSmth<T>(T obj)
        where T : Superclass
    {
    
       //untested but something like this
        Subclass obj2 = (obj as Subclass);   
        if(obj2 != null)
        {
            DoSmth2(obj2);
        }
        //...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created two viewController classes such that one is superclass of another.i have
I have two classes, one of which is a subclass of another, and differs
Lets say I have two classes: class A { [SortOrder(3)] public string Name {
I have two classes: class Player { public string Id { set; get; }
I have two classes, which reference the third: class Data1 { public Named Xxx
I have got two classes, one a subclass of the other (say Animal and
I have two classes Teams and PlayerTeams public class PlayerTeams { public int ID
I have two classes public class News { public virtual int Id { get;
I have two classes that extend the activity class. Each class has it's own
I have two classes namely classA and classB which both inherit from class1 .

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.