从词典值创建元组

时间:2015-11-02 03:55:19

标签: c# winforms

如何使用字典值中的Tuple.Create创建元组?

我有一本字典:

private static Dictionary<string, string> dNameProps = new Dictionary<string, string>();

然后我添加了值:

internal static void InitializeVals()
{
    foreach(var items in lstOfNames)
    var name = item.name + " " + item.item1.ToString(); 
    var prop = item.properties;
    dNameProps.Add(name, prop);
}

我需要从这些值创建一个元组,其名称等于字典中的键

这是我到目前为止所做的:

private static void GetParametersImplementation(string name , params object[] args)
{
    var Nname = name ;
    if (args.Any())
    {
        //string nameX =dNameProps[name]
        var perProperties = Tuple.Create("", args[0]);
    }
}

2 个答案:

答案 0 :(得分:1)

元组数组:

    if (me != 0) {
        if (finalTour != null) {
            Node[] nodes = new Node[5];
            nodes[0] = finalTour;

            MPI.COMM_WORLD.Send(nodes, 0, 5, MPI.OBJECT, 0, 0);
        }
    }
    if (me == 0) {
        for (int i = 1; i < processes; i++) {
            Node[] nodes = new Node[5];
            MPI.COMM_WORLD.Recv(nodes, 0, 5, MPI.OBJECT, MPI.ANY_SOURCE, MPI.ANY_TAG);
            if (nodes[0] != null) {
                if (finalTour != null) {
                    if (finalTour.cost > nodes[0].cost) {
                        finalTour = nodes[0];
                    }
                    minCostPath = finalTour;
                } else {
                    finalTour = nodes[0];
                    minCostPath = finalTour;
                }
            }
        }
    }
    MPI.Finalize();
    if (minCostPath != null) {
        print(size, minCostPath);
    }

答案 1 :(得分:0)

Tuple<string, string>[] lstTuple = 
        dNameProps.Select(kvp => new Tuple<string, string>(kvp.Key, kvp.Value)).ToArray();