如何加入新指南列表?

how to join a list on new guids?

如何将带有 guid 的字符串列表连接到字典中?

我有一个这样的列表:

new List<String> { "alex", "liza", "harry" }

我想创建一个像这样的字典:

new Dictionary<Guid, String> {
        {
            "97085fe7-4717-4b70-95aa-80be9b1bfb47",
            "alex"
        },
        {
            "f88a41c2-27ac-47c5-a967-a4cdc2c6171c",
            "liza"
        },
        {
            "2a6adaac-23b4-4d6e-9fb4-610d4c14e231",
            "harry"
        }
    }

如何zip 随机 Guid 列表和字符串列表

您可以像这样使用 .ToDictionary

var myList = new List<String> { "alex", "liza", "harry" }
var myDictionary = myList.ToDictionary(i => Guid.NewGuid());

>>> Dictionary<Guid, string>(3) { { [06dde7e3-2fdd-4107-a4c5-63bee818abda], "alex" }, { [93029465-11b5-463b-ab04-bebdb1a8e77f], "liza" }, { [8ff8ff05-7bcf-4dd0-bb8d-07231932c3d8], "harry" }

尝试以下操作:

var names = new List<String> { "alex", "liza", "harry" };

var d = names.ToDictionary(n => Guid.NewGuid());