OGeek|极客世界-中国程序员成长平台

标题: c# - 如何在 xamarin ios 中将我的 NSArray 转换为 List<String> [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:21
标题: c# - 如何在 xamarin ios 中将我的 NSArray 转换为 List<String>

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

使用

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

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

我尝试了以下但失败了

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

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



Best Answer-推荐答案


听起来你想要来自 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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4