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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:40:23+00:00 2026-05-19T16:40:23+00:00

It is valid (ie. it compiles and runs) to put an attribute on the

  • 0

It is valid (ie. it compiles and runs) to put an attribute on the generic parameter for a class or a method:

public class MyClass<[My] T>
{
    private void MyMethod<[My] T>()
    {}
}

public class MyAttribute : Attribute
{}

I’ve never seen this used, and am struggling to come up with a reason as to why you would want to.

Is it just a quirk/side-effect of the language specification, or is there a valid/useful reason to put an attribute in this position?

  • 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-19T16:40:24+00:00Added an answer on May 19, 2026 at 4:40 pm

    For the same reason attributes are useful on any construct; they supply meta-data that can be used by Reflection or other post-processors to do various things. For instance, you might have an AOP system that uses an attribute on a type argument to apply certain run-time constraints that otherwise could not be expressed. I’m not sure if there are any systems that actually use these attributes to do anything, but there’s no reason to disallow them as metadata.

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

Sidebar

Related Questions

class someClass { public: int* ptr2Int; }; Is this a valid class (yes it
Possible Duplicate: What are valid values for the id attribute in HTML? Underscores seem
What are the valid values for the eventName attribute when configuring Health Monitoring? <system.web>
Is it generally valid that a macro is used to create a method name?
is this valid void *p = &X; /* some thing */ p += 12;
If an aspx file compiles, is it safe to assume that it is valid
Considers me@there valid. Is not a TLD required? try { foreach (var email in
I have a valid reason for wanting to do this, but it's a long
Is it logically valid to do this: child.frame = parent.bounds Let's say I want
Is it valid C to declare a struct and define values enclosed in {}?

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.