Reputation: 129
How do you go about casting numbers to specific data types?
Example:
253 is 32-bit signed integer
253L is 64-bit signed integer
253D is Double precision float
As you can see you can cast directly to Long and Double, but there are certain problems I have here. I cannot cast to byte, single, 16bit, unsigned...
It becomes a problem when I have to input data into many different functions with arguments of varying data types:
Method1( byte Value );
Method2( sbyte Value );
Method3( ushort Value );
//Etc.
Upvotes: 1
Views: 78
Reputation: 506
Using int.Parse(string) or Convert.ToInt32 will do the trick. Or you could try casting the value expicitly like that:
int age = 53;
Method1((byte) age);
Upvotes: 1
Reputation: 3214
Try using the Convert
class:
http://msdn.microsoft.com/en-us/library/System.Convert_methods(v=vs.110).aspx
e.g.
int myInt = Convert.ToInt32(anything);
Upvotes: 1