我有以下代码:
DateTime[] localTimeArray = GetTimeData<DateTime>();
现在我需要调用 .ToLocalTime()
对于 GetTimeData
返回的数组中的每个元素在将它们复制到新数组之前。
我怎样才能做到这一点而不必手动遍历每个项目?
显然以下内容不起作用:
DateTime[] localTimeArray = GetTimeData<DateTime>().ToLocalTime();
作为GetTimeData
来自外部库,我无法按照评论中的建议在其中添加代码。
最佳答案
尝试
DateTime[] localTimeArray = GetTimeData<DateTime>().Select(x => x.ToLocalTime()).ToArray();
关于c# - 使用扩展方法复制数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54622136/