Open
Description
code:
var dictList = new List<Dictionary<string, string>>
{
new Dictionary<string, string>()
{
{"key1", "value1"},
{"key2", "value2"}
},
new Dictionary<string, string>()
{
{"key3", "value3"},
{"key4", "value4"}
}
};
var mergedDict = dictList
.SelectMany(d => d)
.ToDictionary(kv => kv.Key, kv => kv.Value);
error:
Oops! No applicable member has been found for the expression. The error occurred for expression "." at position 315 near ".SelectMany(d => d)
Full source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Z.Expressions;
namespace ConsoleApp7
{
internal class Program
{
static void Main(string[] args)
{
string code = """
var dictList = new List<Dictionary<string, string>>
{
new Dictionary<string, string>()
{
{"key1", "value1"},
{"key2", "value2"}
},
new Dictionary<string, string>()
{
{"key3", "value3"},
{"key4", "value4"}
}
};
var mergedDict = dictList
.SelectMany(d => d)
.ToDictionary(kv => kv.Key, kv => kv.Value);
""";
try
{
Eval.Execute(code);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
Console.ReadLine();
}
}
}
Metadata
Metadata
Assignees
Labels
No labels