【轉】c#怎樣將object[]轉換為string[]?


object[] objs = new object[] { "1", "2", "3" };
string[] strs = new string[objs.Length];
objs.CopyTo(strs, 0);

當然必須確保你的object每個對象都是字符串。
如果object數組中有多種對象類型如下:
object[] objs = new object[] { "1", 1, 2.3 }; 那另當別論了。
for(int i=0;i<objs.Length;i++)
{
strs[i] = objs[i].ToString();
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。