字符串上的任何()

Any() on String

我不明白幕后发生了什么。 我有一个简单的字符串:

 var aux = "Hello";

如果我 运行:

aux.Any();

它 returns 正确Any() 执行在 System.Core dll:

是否有幕后转换,将字符串转换为可枚举的字符,然后 Any() 验证列表是否为空或...?

提前致谢!

String的定义以

开头
public sealed class String : IEnumerable<char>, IEnumerable, ICloneable, IComparable, IComparable<string?>, IConvertible, IEquatable<string>
{ ...

String 实现接口 IEnumerableIEnumerable<Char>。并且

You can write LINQ queries in C# for ... any collection of objects that supports IEnumerable or the generic IEnumerable interface.

(来自 this article

它是这样工作的,因为 LINQ 只是 extension methods 这些接口。