Csharp/CSharp Tutorial/Data Type/ushort
Версия от 15:31, 26 мая 2010; (обсуждение)
Use ushort as the parameter for overload methods
using System;
class Util
{
public static void Process(short value)
{
Console.WriteLine("short {0}", value);
}
public static void Process(ushort value)
{
Console.WriteLine("ushort {0}", value);
}
}
class MainClass
{
public static void Main()
{
byte value = 3;
Util.Process(value);
}
}short 3
Ushort To Byte convert
using System;
class MainClass
{
static void Main()
{
ushort sh = 10;
byte sb = (byte)sh;
Console.WriteLine("sb: {0} = 0x{0:X}", sb);
sh = 1365;
sb = (byte)sh;
Console.WriteLine("sb: {0} = 0x{0:X}", sb);
}
}sb: 10 = 0xA sb: 85 = 0x55
ushort value
using System;
class MainClass
{
public static void Main(string[] args)
{
ushort myOtherUInt16 = 12000;
Console.WriteLine("Your value is: {0}", myOtherUInt16.ToString());
Console.WriteLine("I am a: {0}\n", myOtherUInt16.GetType().ToString());
}
}Your value is: 12000 I am a: System.UInt16