如何从NameValueCollection获取所有值作为单个字符串?

Ank*_*kar 5 c# linq namevaluecollection

如何将所有值NameValueCollection作为单个字符串键入,
现在我使用以下方法来获取它:

public static string GetAllReasons(NameValueCollection valueCollection)
{
    string _allValues = string.Empty;

    foreach (var key in valueCollection.AllKeys)
        _allValues += valueCollection.GetValues(key)[0] + System.Environment.NewLine;

    return _allValues.TrimEnd(System.Environment.NewLine.ToCharArray());
}
Run Code Online (Sandbox Code Playgroud)

任何简单的解决方案Linq

Paw*_*ger 8

您可以使用以下内容:

string allValues = string.Join(System.Environment.NewLine, valueCollection.AllKeys.Select(key => valueCollection[key]));
Run Code Online (Sandbox Code Playgroud)