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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:56:46+00:00 2026-05-31T06:56:46+00:00

When assigning a default value to a uint parameter in a C# method argument,

  • 0

When assigning a default value to a uint parameter in a C# method argument, as shown in the first code block below, I am presented with the message “A value of type ‘int’ cannot be used as a default parameter because there are no standard conversions to type ‘uint'”, whereas when assigning an int to a uint variable in the method body it is fine.

The code does compile; the warning is provided by means of the red, squiggly underlining in Visual Studio 2010.

void GetHistoricData(uint historyLength = 365) 
{
    uint i = 365; // this is valid
}

This is easily resolved by by using 365U in place of 365, thus:

void GetHistoricData(uint historyLength = 365U) 
{
    // method body
}

I am finding it really difficult to find a good explanation of why it is invalid to assign an int to the uint in the parameter when it is valid to do so elsewhere. Can anyone help me with the ‘light-bulb’ moment I am trying to find?

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

    It compiles for me, with compiler versions of both 4.0.30319.1 and 4.0.30319.17379.

    If you’re using an older version or a different compiler (e.g. a Mono one) then I suspect it’s simply a bug.

    EDIT: If it’s compiling fine (and I can’t provoke a warning at all from the compiler) then I suspect it’s some plug-in, such as ReSharper. (Not that I’m seeing it in ReSharper either…)

    I can’t reproduce this in VS2010.

    I would suggest that you do update the code to the one without the warning, just for the sake of readability – but it’s still valid code without the change.

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

Sidebar

Related Questions

I am having a problem assigning a default value to my Spring Form input
When assigning a default default-value to a field (here false to a bool), FxCop
When assigning a type casted array to codeigniter's session, I get this error: A
I am assigning to an ImageView contacts images using this code: mPhotoView = (ImageView)
I am creating a menu and assigning images to menu items, sometime first item
In Perl, if I want to default a value that might exist, for example
What is the default value of unsigned int in c#? For ex: int, its
From Python docs: sys.excepthook(type, value, traceback) This function prints out a given traceback and
Assigning a Date variable to another one will copy the reference to the same
Need some help assigning a mouseover event to display some icons that start out

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.