托管C ++中的Array :: ConvertAll

时间:2010-12-26 13:28:03

标签: .net arrays parsing c++-cli managed

这是this帖子的延续。

我正在尝试在托管C ++中解析此字符串:

String ^ rgba = "[0.09019608,0.5176471,0.9058824,1]";
cli::array<System::Double> ^ RGB = System::Array::ConvertAll<String,cli::array<System::Double> >((rgba->Substring(1,rgba->Length-2)->Split(',')),double::Parse);

编译器抛出以下错误:

Error   15  error C2770: invalid explicit generic argument(s) for 'cli::array<Type,dimension> ^System::Array::ConvertAll(cli::array<TInput,1> ^,System::Converter<TInput,TOutput> ^)'   

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您为ConvertAll指定了错误的类型参数。你已经指定你正在从字符串数组转换为双数组数组 - 它应该只是从字符串到双精度。

PS尝试将更少的内容填充到单行中会使其更容易阅读!

示例

String^ rgba = "[0.09019608,0.5176471,0.9058824,1]";

array<String^>^ values = rgba->Substring(1,rgba->Length-2)->Split(',');

Converter<String^, double>^ converter =
    gcnew Converter<String^, double>(double::Parse);

array<double>^ RGB = Array::ConvertAll(values, converter);