如何将字符串转换为ushort数组 [英] How to convert a string to an ushort array

查看:325
本文介绍了如何将字符串转换为ushort数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将字符串转换为ushort数组。

How to convert a string to an ushort array..

非常感谢您的帮助。

谢谢,
Lokesh

Thanks, Lokesh

推荐答案

string s = "test";
ushort[] result = s.ToCharArray().Select(c => (ushort)c).ToArray();

不确定这是否是最好的方法,但它应该可以工作。

Not sure if it's the best way, but it should work.

编辑::我不知道字符串已实现 IEnumerable 。所以实际上您只需要:

I didn't know string implemented IEnumerable. So actually you just need:

ushort[] result = s.Select(c => (ushort)c).ToArray();

感谢Jeff指出了这一点。

Thanks to Jeff for pointing that out.

这篇关于如何将字符串转换为ushort数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆