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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:55:51+00:00 2026-05-30T07:55:51+00:00

I suspect the answer is no, but is it possible to do something like

  • 0

I suspect the answer is no, but is it possible to do something like this in C#.NET (v2.0).

class Converter<E>
{
    public E Make(object o)
    {
        return o as E;
    }
}

If not, is it possible to check types like this:

public bool IsType(object o, Type t)
{
    return o is E;
}

I’m not certain about the terminology so it is rather hard to Google for me.
But my guess is that these two problems are related. Any ideas?

  • 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-05-30T07:55:52+00:00Added an answer on May 30, 2026 at 7:55 am

    You can cast o to E using the () Operator:

    class Converter<E>
    {
        public E Make(object o)
        {
            return (E)o;
        }
    }
    

    If you use as, o as E requires E to a be a reference type, because if o is not castable to E, the result is (E)null. You can constrain E to reference types by using the class Constraint:

    class Converter<E> where E : class
    {
        public E Make(object o)
        {
            return o as E;
        }
    }
    

    public bool IsType(object o, Type t)
    {
        return (o != null) ? t.IsAssignableFrom(o.GetType()) : t.IsClass;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suspect this applies to general ASP.Net too but I am not sure. If
I suspect this answer is in SO but I cannot find it. Some reports
I've notice an issue - it feels like a bug but I suspect a
I suspect the answer is no (or at least, not in an intelligent manner),
I suspect the answer to this is No, based purely on the concept of
I have no idea if this is possible but is there a way in
I suspect the answer is no, but I want to check. If I have
I suspect the answer's a pretty definite no, but given the following html and
I've looked around the web for this before, and I suspect the answer is
One day I suspect I'll have to learn hadoop and transfer all this data

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.