现在的位置: 首页 > 综合 > 正文

byte[]和string

2013年03月22日 ⁄ 综合 ⁄ 共 580字 ⁄ 字号 评论关闭
 static void Main()
{
byte[] byt = System.Text.Encoding.Default.GetBytes("你好啊!Event");//string转换byte[]
foreach (byte b in byt)
{
Console.WriteLine(b);//输出196,227,186,195,176,161,163,161,69,118,101,110,116,一个中文两个字节.
}
Console.WriteLine(System.Text.Encoding.Default.GetString(byt));//你好啊!Event
Console.ReadKey();
}
 public static void add(byte bt)
{
byte b = 100;
// checked//在方法里checked会抛出异常.
//{
b += bt;
//}
}
static void Main()
{
int i = 20;
byte b = ((byte)(i + 25));
b += 1;
checked {
Program.add(255);//假定add视图把255加到一个byte中.如果add方法没有checked,在这里是不会抛出异常的.add方法使用checked指令,会抛出异常,但是和当前的checked无关.
}
Console.WriteLine(b);
Console.ReadKey();
}


抱歉!评论已关闭.