将'System.Collections.Generic.IEnumerable <string>'转换为'string [] - c#

我在转换一段代码以使其与.NET3.5兼容时遇到问题。

static Dictionary<string, object> dictionary = new Dictionary<string, object> 
{
    {"key","value"},
    {"key2","value2"},
};

public static string Process(String _string)
{
    var levels = new Dictionary<string, object>
    {
        { "", "" },
        { "-", "Light" },
        { "+", "Heavy" }
    };
    var search = string.Join("and ", from l in levels.Keys
                               from w in dictionary.Keys
                               join m in _string.Split() on string.Concat(l, w) equals m
                               select string.Concat(levels[l], dictionary[w]));

    return search;
}

尝试编译时出现两个错误...

参数2:无法从中转换
“ System.Collections.Generic.IEnumerable”为“ string []”

最佳重载方法匹配“ string.Join(string,string [])”
有一些无效的论点

我考虑过添加.ToArray(),但是我不知道在哪里。

参考方案

像这样使用ToArray

var search = string.Join("and ", (from l in levels.Keys
                           from w in dictionary.Keys
                           join m in _string.Split() on string.Concat(l, w) equals m
                           select string.Concat(levels[l], dictionary[w])).ToArray());

如何解析Dapper System.Data.DataException HResult = 0x80131501 InvalidCastException从'System.String'到'System.Uri'的无效转换 - c#

最近,我重构了一些代码,这些代码导致将实体的某些属性的类型从System.String更改为System.URI。有问题的属性名称包含子字符串URI或URL,并且SonarLint静态代码分析器建议将代码重构为对这些属性使用System.URI类型而不是System.String,这在我们的解决方案中很有意义。在这个项目中,我们利用StackExchange…

IAsyncOperation <IReadOnlyList <UserNotification >>'不包含'GetAwaiter'的定义 - c#

我正在使用Visual Studio 2017专业版。我一直在遵循本指南:https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/notification-listener我的问题代码如下:using System.Collections.Generi…

无法从ArrayList <String>转换为List <Comparable> - java

当我写下面的代码时,编译器说 无法从ArrayList<String>转换为List<Comparable>private List<Comparable> get(){ return new ArrayList<String>(); } 但是当我用通配符编写返回类型时,代码会编译。private List&l…

无法在Codeigniter / PHPExcel中重新声明类Excel错误 - php

我想在Excel文件中导出一些数据,但出现此错误。遇到PHP错误严重性:编译错误消息:无法重新声明Excel类文件名:libraries / EXcel.php行号:9我尝试了一些方法,但没有人适合我。像1 2这是我的EXcel.php代码<?php if (!defined('BASEPATH')) exit('No d…

为什么要使用Func <string>而不是string? - c#

为什么要使用Func<string>而不是string?我的问题特别是关于this回购。有问题的行是22: private static Func<string> getToken = () => Environment.GetEnvironmentVariable("GitHubToken", Enviro…