在我的 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
所以您问题中的 Actor 没有使用正确的变量。
有很多方法可以做到这一点,但我建议您使用 .NET API,而不是 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/