如何将KeyValuePair传递到这个方法中?

huangapple go评论70阅读模式
英文:

How do I pass the KeyValuePair into this method?

问题

如何将KeyValuePair传递到这个方法中,接受ICollection<KeyValuePair<string, string>>

如果我的标头名称是'auth',标头值是'local'

_restActions.ExecutePostRequest(resource, body, {在这里放什么});

英文:

How do I pass the KeyValuePair into this method, accepting ICollection<KeyValuePair<string, string>>?

如何将KeyValuePair传递到这个方法中?

If my header name is 'auth' and the header value is 'local'

_restActions.ExecutePostRequest(resource, body, {WHAT GOES HERE});

答案1

得分: 3

你可以传递一个实现了ICollection<KeyValuePair<string, string>>Dictionary<string, string>,我认为这允许使用最简洁的实例化语法:

_restActions.ExecutePostRequest(
    resource, 
    body, 
    new Dictionary<string, string>{{"one", "two"}, {"foo", "bar"}});
英文:

You can pass a Dictionary<string, string> which implements ICollection<KeyValuePair<string, string>> and, I would argue, allows the most concise instantiation syntax:

_restActions.ExecutePostRequest(
    resource, 
    body, 
    new Dictionary<string, string>{{"one", "two"}, {"foo", "bar"}});

答案2

得分: 1

由于headers参数上有null(默认值),所以您无需传递任何内容。
如果您确实想传递一些内容,那么可以是类似于new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("content-type", "text/plain") } 的任何内容。

英文:

You do not need to pass anything since there is null on headers parameter (default value).
If you do want to pass something then it would be anything like new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("content-type", "text/plain") }

huangapple
  • 本文由 发表于 2023年7月13日 19:49:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定