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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:22:12+00:00 2026-06-13T23:22:12+00:00

I have int variable with value 820924 when I’m trying to convert it like

  • 0

I have int variable with value 820924
when I’m trying to convert it like that:

(uint)data[structure["MICROSECONDS"].Index]

it doesn’t work.

This doesn’t work as well

unchecked((uint)data[structure["MICROSECONDS"].Index])

I receive Specified cast is not valid. exception.

Data stores object, but at run time I should try to convert to int. I’m almost sure. I’ve printed object value it was 820924, however I don’t know how to print object type, but it must be int.

Code:

object value = data[structure["MICROSECONDS"].Index];
Console.WriteLine("xx MICROSECONDS type " + value.GetType());
Console.WriteLine("xx casting " + value);
Console.WriteLine("xx cast ok" + (uint)value);

Result:

xx MICROSECONDS type System.Int32
xx casting 820924
  • 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-13T23:22:13+00:00Added an answer on June 13, 2026 at 11:22 pm

    First of all you should check the type of your value. You can do it by calling obj.GetType() method (either in your code directly or in Immediate window).

    If it is int then you can do:

    uint u = (uint) (int) obj;
    

    Please note that it differs from your cast because it casts to int and then converts to uint while you were trying to cast to uint. int cannot be cast to uint and that is why you get the InvalidCastException. int can be only converted to uint. It is confusing that both conversion and cast operators look same in code: u = (uint) x.

    Easier thing you can do is calling a specific method from Convert class:

    uint u = Convert.ToUInt32(x);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class like this class variable { public: variable(int _type=0) : type(_type), value(NULL),
I have a int variable witch holds the old battery value it is declared
I have string value and Type of some variable (For example int and 32
I have declared a variable like this @{ int i = 1; } Now,
I'm working on XSLT 1.0 version I have declared an int variable that have
Are the primitive data types like int & short thread-safe in Java? I have
I have a variable that very rarely gets an incorrect value. Since the system
You initialize an int variable defined within a method to have a value of
I am trying to change a variable value, but I only have the name
Possible Duplicate: Swapping two variable value without using 3rd variable we have int a=4;

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.