Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何删除c#中的重复代码od字典?_C#_Dictionary - Fatal编程技术网

如何删除c#中的重复代码od字典?

如何删除c#中的重复代码od字典?,c#,dictionary,C#,Dictionary,我正在使用字典显示消息。为此,我使用Dictionary添加消息并解析它以显示函数。下面是我的代码: var dict = new Dictionary<string,string>(); dict.Add("",""); service.displaymessage(dict); var dict=newdictionary(); dict.Add(“,”); 服务显示消息(dict); 在我的类中重复此代码,以便在每个函数中添加不同的消息。 如何最小化这些行?在每个重复代

我正在使用
字典
显示消息。为此,我使用
Dictionary
添加消息并解析它以显示函数。下面是我的代码:

var dict = new Dictionary<string,string>();

dict.Add("","");

service.displaymessage(dict);
var dict=newdictionary();
dict.Add(“,”);
服务显示消息(dict);
在我的类中重复此代码,以便在每个函数中添加不同的消息。
如何最小化这些行?

在每个重复代码中有多少个
dict.Add(“,”)
以及。。。您是否如您的问题所示,为每次调用
Add
都创建一个
new
字典?您可以创建一个方法,该方法接受字典、添加元素并显示它。为什么您需要
字典
来只传递一条消息?您是否需要从一个函数传递多条消息?是,有多条消息