Is it possible to store functions in a dictionary?

前端 未结 5 784
萌比男神i
萌比男神i 2021-02-01 14:46

I have a message coming into my C# app which is an object serialized as JSON, when i de-serialize it I have a \"Name\" string and a \"Payload\" string[]

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-01 15:28

    Yes.

    var functions = new Dictionary>();
    functions.Add("head", x => x.Take(1).ToArray());
    functions.Add("tail", x => x.Skip(1).ToArray());
    var result = functions["tail"](new [] {"a", "b", "c"});
    

提交回复
热议问题