Key value pairs in C# Params

前端 未结 8 2632
后悔当初
后悔当初 2021-02-11 14:55

I\'m looking for a way to have a function such as:

myFunction({\"Key\", value}, {\"Key2\", value});

I\'m sure there\'s something with anonymous

8条回答
  •  没有蜡笔的小新
    2021-02-11 15:35

    Use a Dictionary ...

    void Main()
    {
        var dic = new Dictionary();
        dic.Add( "Key1", 1 );
        dic.Add( "Key2", 2 );   
    
        MyFunction( dic ).Dump();
    }
    
    public static object MyFunction( IDictionary dic )
    {
       return dic["Key1"];
    }
    

提交回复
热议问题