C#.net 关于类型转换
2010-09-08 23:17
441 查看
关于类型转换
byte[]->string:
byte []pDst = new byte[size];
string strData = Encoding.Default.GetString(pDst, 0, size);
在.netCF中,若byte数组中间有数据为0x00,则会报错"超出范围"
string->byte[]:
string strSrc = "中12国3";
byte[] bData = new byte[200];
bData = System.Text.Encoding.Default.GetBytes(strSrc);
char[]->string
char[] cData = new char[size];
string strData = new string(cData);
string->char[]
string strData="hello";
char []cDst = new char [100];
strData.CopyTo(0, cDst, 0, strData.Length);
string->byte[]
string strData = "hello";
byte []bData = new byte[100];
Encoding.Default.GetBytes(strData, 0, strData.Length, bData, 0);
byte*->byte[]
byte* pSrc;
byte[] pDst = new byte[size];
Marshal.Copy(new IntPtr(pSrc), pDst, 0, size);
byte*->char[]
byte* pSrc;
char[] pDst = new char[size];
for (int i = 0; i < size; i++)
{
pDst[i] = Convert.ToChar(pSrc[i]);
}
byte[]->string:
byte []pDst = new byte[size];
string strData = Encoding.Default.GetString(pDst, 0, size);
在.netCF中,若byte数组中间有数据为0x00,则会报错"超出范围"
string->byte[]:
string strSrc = "中12国3";
byte[] bData = new byte[200];
bData = System.Text.Encoding.Default.GetBytes(strSrc);
char[]->string
char[] cData = new char[size];
string strData = new string(cData);
string->char[]
string strData="hello";
char []cDst = new char [100];
strData.CopyTo(0, cDst, 0, strData.Length);
string->byte[]
string strData = "hello";
byte []bData = new byte[100];
Encoding.Default.GetBytes(strData, 0, strData.Length, bData, 0);
byte*->byte[]
byte* pSrc;
byte[] pDst = new byte[size];
Marshal.Copy(new IntPtr(pSrc), pDst, 0, size);
byte*->char[]
byte* pSrc;
char[] pDst = new char[size];
for (int i = 0; i < size; i++)
{
pDst[i] = Convert.ToChar(pSrc[i]);
}
相关文章推荐
- C#.NET 中的类型转换
- .NET 关于类型转换的是是非非
- C#类型转换中关于“四舍六入,五看奇偶”
- C#.NET 中的类型转换
- c# .net中的类型转换
- C#.NET 中的类型转换 (转)
- asp.net(c#)数据类型格式转换大全
- C#.NET 中的类型转换
- 关于C#数据类型之间转换的问题
- C#.NET 中的类型转换
- C#.NET 中的类型转换
- C# .Net中的类型转换
- 关于C#的类型转换
- C#.NET 中的类型转换
- C#.NET 中的类型转换
- ASP.NET AJAX客户端编程教程(3)——让JavaScript和C#无障碍沟通:数据类型自动转换&序列化
- ASP.NET语言(C#)类型转换
- C#.NET 中的类型转换
- C#.NET 中的类型转换
- 关于C# 类型转换的问题