gpt4 book ai didi

c# - 如何在 xamarin ios 中将我的 NSArray 转换到 List

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:50 28 4
gpt4 key购买 nike

在我的 xamarin ios 项目中,我正在从文件中获取一些数组

使用

NSArray TimeFilePath = NSBundle.MainBundle.PathForResource("Time","txt");
arrTime = NSArray.FromFile(TimeFilePath);

现在我必须将 TimeFilePath 转换为列表

我尝试了以下但失败了

List<string>items = (List<string>)TimeFilePath;

帮我看看如何在 C# 中将 NSArray 转换为 List

最佳答案

听起来你想要 arrTime 的列表(不是 TimeFilePath)因为 PathForResource 返回一个 string 所以您在问题中的 cast 没有使用正确的变量。

有很多方法可以做到这一点,但我建议您使用 .NET 而不是 Apple API 来实现这一点,例如

var TimeFilePath = NSBundle.MainBundle.PathForResource("Time","txt");
var lines = System.IO.File.ReadLines (TimeFilePath);
var arrTime = List<string> (lines);

关于c# - 如何在 xamarin ios 中将我的 NSArray 转换到 List<String>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31679955/

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