如何从字符串生成序列? [英] How to generate a sequence from a string?

查看:73
本文介绍了如何从字符串生成序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个字符串显示为一个字符序列-我知道一个字符串是可枚举的,但是我的代码期望seq< char>并且它不会接受字符串=,那么将字符串表示为seq< char的最简单方法是什么?类型?

I want to expose a string as a sequence of chars - I know a string is enumerable but I have code that expects a seq<char> and it wont accepts a string = so what is simplest way to represent a string as a seq<char? type?

Thx

推荐答案

由于System.String已经实现IEnumerable,因此我们需要的功能是

As System.String already implements IEnumerable, the function we need is

Seq.cast<char>

它接受未类型化的字符序列,并为其提供基础序列成员的实际类型.

which takes the untyped sequence of characters and gives it the actual type of the underlying sequence members.


这篇关于如何从字符串生成序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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