简体   繁体   English

如何转换 C# 列表<byte>到 NSData?

[英]How does one convert C# List<byte> to NSData?

I'm working on a Xamarin Forms app (don't ask) and have to write platform-specific code for the iOS solution.我正在开发 Xamarin Forms 应用程序(不要问),并且必须为 iOS 解决方案编写特定于平台的代码。 I'm primarily an iOS developer, so my C# is lacking in certain areas.我主要是一个 iOS 开发人员,所以我的 C# 在某些方面缺乏。

The iOS CBPeripheral.WriteValue call requires an NSData object. iOS CBPeripheral.WriteValue 调用需要一个 NSData 对象。

I currently have a C# List data structure.我目前有一个 C# List 数据结构。 So I need to convert that to NSData in order to write the value.所以我需要将它转换为 NSData 才能写入值。

I've searched on the usual candidates (SO, etc,) but haven't found a solution to my particular problem.我已经搜索了通常的候选人(SO 等),但还没有找到解决我的特定问题的方法。

I'd appreciate any help people can provide.我很感激人们可以提供的任何帮助。

if MyList is a List<byte>如果MyListList<byte>

var arr = MyList.ToArray<byte>();
var data = NSData.FromArray(arr)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM