문제

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.

도움이 되었습니까?

해결책

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);

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top