TechArena Community How can i convert c# 'uint' to 'int'

#1
19-05-2009
 Member Join Date: Jan 2009 Posts: 124
How can i convert c# 'uint' to 'int'

I would like to know that how can i convert convert c# 'uint' to 'int' on my system. Can any body provide me the correct logical solution for the above issue? Does any body knows that how to convert 'uint' to 'int' by using C# programming language? Kindly provide me the correct information on the above issue. Any kind of help on the above issue would be appreciated.
#2
19-05-2009
 Member Join Date: May 2008 Posts: 2,293
Re: How can i convert c# 'uint' to 'int'

When an integer literal has no suffix, its type is the first of these types in which its value can be represented: int, uint, long, ulong. In this example, it is uint.

You can also use the suffix u or U, like this:
Quote:
 uint myUint = 123U;
When you use the suffix U or u, the literal type is determined to be either uint or ulong according to its size. In this example, it is uint.
#3
19-05-2009
 Member Join Date: Oct 2005 Posts: 2,389
Re: How can i convert c# 'uint' to 'int'

In order to do this, you'll need to convert each element in a loop. You need to do the following code for doing so.

Quote:
 private byte[] ConvertFromUInt32Array(UInt32[] array) { List results = new List(); foreach(UInt32 value in array) { byte[] converted = BitConverter.GetBytes(value); results.AddRange(converted); } return results.ToArray(); }
#4
02-06-2009
 Member Join Date: Jun 2009 Posts: 1
Re: How can i convert c# 'uint' to 'int'

This code:
uint x = 5;
int y = (int)x;
Console.WriteLine("The value of int y is {0}",y.ToString());
produces this output:
The value of int y is 5

 Tags: