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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:55:56+00:00 2026-06-07T23:55:56+00:00

for example, I have a ( non-static ) class Foo<T> I would like to

  • 0

for example, I have a (non-static) class Foo<T>

I would like to add a method bar() for Foo, however this method should only work for Foo<int>.

Because we cannot overload type constraints,
Do I have to create an extension method in a separate static class bar(this Foo<int> myFoo)?

  • 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-07T23:55:57+00:00Added an answer on June 7, 2026 at 11:55 pm

    Basically, yes. C# (and the CLR in general) does not support template specialization known from C++.

    Type parameters are meant to be used when your class’es implementation doesn’t care about the actual type at all.

    As an alternative, add a runtime check to make sure the method is only being called on typeof(T) == typeof(int).

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

Sidebar

Related Questions

Example: I have a selector like this, which I give to another method as
First let's establish this. I have public abstract class Foo { public static void
Suppose you have some method that could be made static, inside a non-static class.
I have this extension method for my BusinessObject class: public static class Extensions {
Example: I have a method -myFooBarMethod:withFoo:bar:moreFoo: and inside the implementation of that method I
First I would like to say that I have only worked with java for
Possible Duplicate Why can't I have a non-integral static const member in a class?
I have the following variable in a class named Example: private static int number;
I have a Static helper class implemented that helps cache and retreive some read-only,
Can I have an identity (unique, non-repeating) column span multiple tables? For example, let's

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.