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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:11:07+00:00 2026-05-11T06:11:07+00:00

I saw the following line of code: class Sample<T,U> where T:class where U: struct,

  • 0

I saw the following line of code:

class Sample<T,U> where T:class where U: struct, T 

In the case above, parameter U is value type, and it derives from reference type T.

How can that line be legal?
Also, if a value type inherits from a reference type, where is memory allocated: heap or stack?

  • 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-11T06:11:08+00:00Added an answer on May 11, 2026 at 6:11 am

    Contrary to another answer, there are types beyond T=System.Object where this compiles:

    class Samplewhere T:class where U:struct, T 

    The ‘T : class’ constraint doesn’t actually mean that T has to be a class. It means T has to be a reference type. That includes interfaces, and structs can implement interfaces. So, for example, T=IConvertible, U=System.Int32 works perfectly well.

    I can’t imagine this is a particularly common or useful constraint, but it’s not quite as counterintuitive as it seems at first sight.

    As to the more general point: as Obiwan Kenobi says, it all depends on your point of view. The CLI spec has quite a complicated explanation of this, where ‘derives from’ and ‘inherits from’ don’t mean quite the same thing, IIRC. But no, you can’t specify the base type of a value type – it’s always either System.ValueType or System.Enum (which derives from System.ValueType) and that’s picked on the basis of whether you’re declaring a struct or an enum. It’s somewhat confusing that both of these are, themselves, reference types…

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Check the following pages: http://homepage.cs.uri.edu/courses/fall2007/csc406/Handouts/eclipseTutorial.pdf http://wikimix.blogspot.com/2006/11/using-eclipse-as-c-development_05.html http://www.benjaminarai.com/benjamin_arai/index.php?display=/eclipsecygwingcc.php May 12, 2026 at 1:10 am
  • Editorial Team
    Editorial Team added an answer This doesn't really have anything to do with Hibernate. You're… May 12, 2026 at 1:10 am
  • Editorial Team
    Editorial Team added an answer Use htmlspecialchars to encode just the HTML special characters &,… May 12, 2026 at 1:10 am

Related Questions

I'm writing a method to return an 'asset' row from the database. It contains
I have a stored procedure with the following header: FUNCTION SaveShipment (p_user_id IN INTEGER,
I've written the following (very simple) control for use in an application (comments removed
In most JSON serializers/deserializers, the key part in a javascript dictionary/hash array is written

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.