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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:04:16+00:00 2026-06-13T18:04:16+00:00

Can somebody explain me the need in C# language for typeof(SomeGenericType<> ), with no

  • 0

Can somebody explain me the need in C# language for typeof(SomeGenericType<>), with no concrete parameters specified.

I put together the following example:

        var t1 = typeof(Nullable<>);
        var t2 = typeof(Nullable<int>);
        var q = 1 as int?;

        var b1 = t1.IsInstanceOfType(q); //false
        var b2 = t2.IsInstanceOfType(q); //true

I first thought typeof(Nullable<>) is “more generic” than t2, which specifies generic parameter int, but b1 turns out to be false – so instance of int? is not instance of Nullable<>.

So how a variable should be defined for b1 to be true? what practical uses does it have?

  • 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-13T18:04:18+00:00Added an answer on June 13, 2026 at 6:04 pm

    So how a variable should be defined for b1 to be true?

    It can’t. (In fact, with Nullable<T> you’ll run into interesting boxing problems anyway, but there we go…)

    At execution time, values are always instances of closed types. Nullable<>, List<> are open generic types. It’s never useful to call IsInstanceOfType on such a type. That doesn’t mean it’s useless though.

    Typically open types are used in reflection. For example:

    public IList CreateList(Type elementType)
    {
        Type closedType = typeof(List<>).MakeGenericType(elementType);
        return (IList) Activator.CreateInstance(closedType);
    }
    

    There can be code high up which is generic, but calls into lower levels passing in Type values instead – the list could then go back up the stack and be cast to IEnumerable<T> for the appropriate value of T.

    Likewise you may want to create a closed type with reflection to call a method on it, etc.

    You can also use it to find out whether a particular type implements a generic interface for some type argument – for each interface implemented, you can find out if it’s generic, get the generic type definition, and see whether that’s equal to (say) IEnumerable<>.

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

Sidebar

Related Questions

Can somebody explain to me why the following works: template<class T> class MyTemplateClass {
Can somebody explain why the following code is not valid? Is it because the
Can somebody please explain me why I need to html_entity_decode the $reversecaption two times
I have some question about the following switch in Linux Kernel, somebody can explain
I need to clear a basic concept. This code works fine. Can somebody explain
Can somebody explain to me the following snippet of assembly: mydiv: pushl %ebp movl
Can somebody explain to me what the below code is doing. before and after
Can somebody explain to me what this does in javascript? (function (x,y){}(x,y)); or this
Can somebody explain why the .Net framework team decided that a delegate without subscribers
Can somebody explain the main differences between (advantages / disadvantages) the two implementations? For

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.