C# MVC 交换字典中键和值的位置

C# MVC swap position of keys and values in dictionary

我做了一个字典如下:

new Dictionary<string, IList<string>>();

现在我将键和值设置到两个不同的列表框中。当我点击第一个带有键的列表框时,它会在第二个列表框中显示关联的值,例如

Key:
Integration

Values:
Identify the safety hazards
Locate and describe the safety devices

列表框如下所示:

我现在想交换 "Identify the safety hazards" 和 "Locate and describe the safety devices" 的值,如下图所示:

它在视觉上与 javascript 一起工作,但词典仍然相同。我必须在字典中交换它。

有人可以帮助我吗?真的很重要。

谢谢!

在我看来,您的密钥是课程名称,ILists 包含该课程的所有任务

为了交换任务的位置,您不需要交换键和值,而是交换它们在列表中的顺序

类似于

void Swap(IList<string> list, int a, int b)
{
    string temp = list[a];
    list[a] = list[b]
    list[b] = temp;
}