gpt4 book ai didi

c# - 将对象 [,] 转换为字符串 [,]?

转载 作者:可可西里 更新时间:2023-11-01 08:22:51 35 4
gpt4 key购买 nike

如何将 object[,] 转换为 string[,]

Object[,] myObjects= // sth
string[,] myString = // ?!? Array.ConvertAll(myObjects, s => (string)s) // this doesn't work

任何建议表示赞赏。

编辑:当然,循环解决方案显然可以做到这一点,但是我设想了一个在代码和性能方面都更优雅的解决方案。

EDIT2:object[,] 当然包含 string(和数字,但现在这并不重要)。

最佳答案

你可以这样分配空间

string[,] myString = new string[myObjects.GetLength(0),myObjects.GetLength(1)];

然后一些循环应该可以正常工作,像这样:

for(int k=0;k < myObjects.GetLength(0);k++)
for(int l=0;l < myObjects.GetLength(1);l++)
myString[k,l] = myObjects[k,l].ToString();

关于c# - 将对象 [,] 转换为字符串 [,]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16297834/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com