(
1)C#中
char
[]与
string互相转换的写法:
string 转换成 Char []
string ss ="abcdefg";
char [] cc =ss.ToCharArray();
Char [] 转换成string
string s =new string(cc);
-- ------------------------------------------------
( 2) C#中 byte []与 string互相转换的写法:
byte [] 转换成string
byte [] bb = Encoding.UTF8.GetBytes(ss);
string s =Encoding.UTF8.GetString(bb);
string 转换为 byte []
byte [] bytes;
string str = "abc";
System. Text.ASCIIEncoding ascill = new ASCIIEncoding();
bytes = ascill.GetBytes( str);
string 转换成 Char []
string ss ="abcdefg";
char [] cc =ss.ToCharArray();
Char [] 转换成string
string s =new string(cc);
-- ------------------------------------------------
( 2) C#中 byte []与 string互相转换的写法:
byte [] 转换成string
byte [] bb = Encoding.UTF8.GetBytes(ss);
string s =Encoding.UTF8.GetString(bb);
string 转换为 byte []
byte [] bytes;
string str = "abc";
System. Text.ASCIIEncoding ascill = new ASCIIEncoding();
bytes = ascill.GetBytes( str);
(
3)将一整数逆序,如987654321变为123456789。
//方法一:倒序循环
int [] intArray = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
for ( int i = intArray.Length - 1; i >= 0; i -- )
{
//intArray [ i ];
}
//方法二:使用反转函数Reverse
int [] newArrary = intArray. Reverse().ToArray();
//方法三:C#中char []与string互相转换的写法:
string strNum = " 9876543210";
char [] reversed = strNum. Reverse().ToArray();
string newStrNum = new string(reversed);
//方法一:倒序循环
int [] intArray = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
for ( int i = intArray.Length - 1; i >= 0; i -- )
{
//intArray [ i ];
}
//方法二:使用反转函数Reverse
int [] newArrary = intArray. Reverse().ToArray();
//方法三:C#中char []与string互相转换的写法:
string strNum = " 9876543210";
char [] reversed = strNum. Reverse().ToArray();
string newStrNum = new string(reversed);
(4)、一、数组(Array)转换为枚举(Enum)类型 enum TypeName { a, b, c } 方法: string[] names = new string[] { "a", "b", "c" }; TypeName[] typeNames = names.Select(t => (TypeName)Enum.Parse(typeof(TypeName), t)).ToArray(); 字符串转换为枚举类型: TypeNametype=(TypeName)Enum.Parse(typeof(TypeName), 'a') 二、枚举(Enum)类型转换为数组(Array) public enum EmploymentTypeEnum { FullTime, Apply, PartTime, } string[] tmp = Enum.GetNames(typeof(EmploymentTypeEnum));