简体   繁体   English

如何在C#XML文档中标记代码

[英]How to tag code in C# XML documentation

I have this function: 我有这个功能:

public static string Join(this IEnumerable<string> strings, string separator)
{
    return string.Join(separator, strings.ToArray());
}

which I want to document. 我要记录。
I want the <return> tag to say string.Join(separator, strings.ToArray()) since to anyone able to read C# code this says more than a thousand words. 我希望<return>标签说string.Join(separator, strings.ToArray())因为任何能够阅读C#代码的人都说超过一千个单词。 However, when I use 但是,当我使用时

<return>string.Join(separator, strings.ToArray())</return>

then string.Join(separator, strings.ToArray()) will be formatted as plain text, which makes it almost unreadable. 然后string.Join(separator,strings.ToArray())将被格式化为纯文本,这使得它几乎不可读。 So I tried 所以我试过了

<return><code>string.Join(separator, strings.ToArray())</code></return>

but this always creates a new paragraph... 但这总是创造一个新的段落......

So here's my question: 所以这是我的问题:
Is there a way to format a piece of text so that it appears as if it were code? 有没有办法格式化一段文本,使其看起来好像是代码? I'd be satisfied with a fixed-width font. 我对固定宽度的字体感到满意。

The <c> tag sounds like it's what you're looking for. <c>标签听起来像是你正在寻找的东西。 Check out MSDN's tag reference for more details. 有关更多详细信息,请查看MSDN的标记参考

That said, are you sure you want the documentation to refer directly to the actions performed by the function? 也就是说,您确定要文档直接引用该函数执行的操作吗? What if you decide to change the implementation later? 如果您决定稍后更改实施,该怎么办? I know this is a pretty trivial example, but food for thought! 我知道这是一个非常简单的例子,但值得深思! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM