int數組轉換為string字元串
将數值數組拼合為字元串,一直使用循環的方式,代碼雖簡單,但總想更簡潔,重構嘛
int[] intArray = new int[] { 1, 2, 3, 4, 5 };
string result = string.Empty;
for (int i = 0; i < intArray.Length; i++)
{
if (!string.IsNullOrEmpty(result))
result += "," + intArray[i];
else
result = intArray[i].ToString();
}
今天才知道真的有小技巧,簡潔的可愛!
int數組轉有分隔符的字元串
int[] ints = { 1, 2, 3 };
string[] strs = Array.ConvertAll<int, string>(ints, delegate(int input) { return input.ToString();});
string result = string.Join(";", strs);
//author:gisrsman
int數組轉string[]數組也不需要寫循環
int[] ints={1,2,3,4};
List list = Arrays.asList(ints);
String[] arr = (String[])list.toArray(new String[ints.length]);
//author:gisrsman
int[] ints = { 1, 2, 3 };
string[] output = Array.ConvertAll<int, string>( ints, i => i.ToString() );
字元串數組排序
//arrID 是已有的字元串數組
IOrderedEnumerable<string> enumStr= arrID.OrderBy(x => x);
string[] newArrID = enumStr.ToArray<string>();
參考: C# 如何對字元串數組排序
C#字元串數組中含數字時的排序
轉載于:https://www.cnblogs.com/GISRSMAN/p/5728595.html