c# - 如何在 xamarin ios 中将 NSArray 转换为 List<String>

标签 c# ios xamarin xamarin.ios nsarray

在我的 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/

相关文章:

ios - 自定义 Google map 样式在 iPad 上不起作用

ios - 内置联系人应用程序是否有自定义 URL 方案?

xamarin - 如何通过默认系统 pdf 应用程序中的 FileProvider 打开 Xamarin.Android 中内部创建的 pdf?

c# - Database.BeginTransaction 与 Transactions.TransactionScope

c# - C#WinForms应用程序显示许多任务栏图标

c# - 从服务器异步接收数据包?

ios - Xamarin 中的 UIInterfaceOrientationIsPortrait

c# - 使用 LINQ 选择最频繁的值

ios - 在制作自定义 UIButton 时,以 NSException 类型的未捕获异常终止

c# - Visual Studio 中的 Xamarin iOS——调试语句被记录两次