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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:37:31+00:00 2026-06-09T15:37:31+00:00

I have update function that I’d like to overload according to the input parameter

  • 0

I have update function that I’d like to overload according to the input parameter (whether it is value type or reference type)

public void Update<T>(T item) where T : ValueType

the compiler has error and it insist I cannot use valuetype (and couple more as a constraint).
should I give up or is there a neat way to overload method according to my desired types?

  • 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-09T15:37:33+00:00Added an answer on June 9, 2026 at 3:37 pm

    You can use where T : struct to enforce that T is a non-nullable value type (this doesn’t work with Nullable<T>, despite that being a value type).

    However, this won’t help your bigger goal, as you can’t overload by type constraints – so this is invalid:

    // Invalid overloading
    void Foo<T>(T item) where T : class
    void Foo<T>(T item) where T : struct
    

    Basically although the number of type parameters is part of the signature of the method (in terms of overloading), the names and constraints aren’t.

    There are horrible ways round this, but I’d recommend using different method names instead.

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

Sidebar

Related Questions

I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;
I have a function that takes another function as a parameter. Something like this
I have a function that does a long task and I want to update
I have a function that's called hundreds of thousands of times per update, and
I have a simple function that calls other functions: function update() { updateMissiles(); updatePlayer;
I have the following function that I doesn't work so far. I would like
Here's my issue. I have a javascript function that update a div when i
I have a function that has a signature of Update(IEnumberable<INotifyPropertyChanging> things) and a class
I have a base class Foo that has an Update() function, which I want
Update Added jsfiddle - see bottom of post I currently have a function that

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.