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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:31:51+00:00 2026-05-16T18:31:51+00:00

Is there a way to constraint a generic type to only integral type? In

  • 0

Is there a way to constraint a generic type to only integral type?

In example, if I have a method

T[] sort<T>(T[] data) where : T ... {}

what would I put as constraint if I wanted to ensure the parameter will be some sort of integral type?

I have tryed looking at MSDN however it does not seem to mention anything about constraining and primitive types.

Thank you for your help.

  • 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-16T18:31:52+00:00Added an answer on May 16, 2026 at 6:31 pm

    Nope. I asked this question before with VB.Net.

    Generic Classes (T) – Specifying from a Range of Types VB.Net

    As quoted from the page above:
    Also, you mentioned constraining to numerics, but I don’t think you can constrain to just that. You can however constrain to just primitive types (on the stack) and not allow objects (on the heap) by doing this: Public Structure Statistic(Of t As {Structure, IComparable}).

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

Sidebar

Related Questions

Is there a way to create a Generic Method that uses the new() constraint
Is there some way to have a generic type with a parameterless constructor that
Is there a way you can do this ? I would like to have
Is there a way to declare a generic function that the generic type is
Is there a way in Boo to express some constaints on generic types as
Is there a way to implement a CHECK constraint that checks a value against
I was wondering if there exists any way to set a constraint on the
Is there a way to perform data validation using CHECK constraints in t-sql and
Is there a way to constrain one type parameter to be derived from another?
I want to write a generic function that has a constraint on the type.

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.