c# - 枚举是否需要 string.ToCharArray()?

标签 c# enumeration securestring

为什么有人会在枚举其中的字符之前将字符串转换为 char[]?在网上找到的用于初始化 System.Security.SecureString 的常规模式如下:

SecureString secureString = new SecureString();
foreach (char c in "fizzbuzz".ToCharArray())
{
    secureString.AppendChar(c);
}

调用 ToCharArray() 对我来说毫无意义。有人能告诉我这里是否错了吗?

最佳答案

string工具 IEnumerable<char> ,在这种情况下没有必要。唯一一次需要ToCharArray是您实际上需要一个数组的时候。

我的猜测是大多数调用 ToCharArray 的人不知道string工具 IEnumerable (尽管据我所知它总是如此)。

关于c# - 枚举是否需要 string.ToCharArray()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5811885/

相关文章:

c# - 在 ASP.NET 中使用 SecureString 有什么好处吗?

c# - 使用 Base64 编码将字节数组转换为 SecureString 的安全方法

C# NLog 性能类变量

c# - Tag Helper - 添加集合中的所有属性

c# - 从我的 WPF 应用程序和 C# 库跟踪内存中的敏感数据

enumeration - 查找表最佳实践 : DB Tables. .. 或枚举

asp.net - 迭代字典项时如何更新值?

c# - 一个且只有一个参数为真时返回的运算符

c# - 在特殊字符后修剪 c# 中的字符串

c++ - C++ 中 "enumeration type"和 "enumerated type"有什么区别?