我如何逃脱在C#注释字符? [英] How do I escape characters in c# comments?

查看:95
本文介绍了我如何逃脱在C#注释字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我意识到,我不知道如何在C#注释转义字符。我想记录一个通用的C#类,但我不能写一个适当的例子,因为我不知道如何逃脱的< > ; 字符。我一定要使用&放大器; LT; &放大器; GT; ?我不喜欢,如果这是因为我想可以很容易地读取实际文件中的注释,所以我不必产生某种代码文件,以便能够读取示例代码的情况。

I realized today that I don't know how to escape characters in comments for C#. I want to document a generic C# class, but I can not write a proper example since I don't know how to escape the < and > characters. Do I have to use &lt; and &gt;? I don't like if that is the case since I want to make it easy to read the comment in the actual document so I don't have to generate some kind of code document to be able to read the example code.

推荐答案

如果你需要逃避XML注释字符,你需要使用的字符实体,所以< 将需要被转义为&放大器; LT; ,因为在你的问题。

If you need to escape characters in XML comments, you need to use the character entities, so < would need to be escaped as &lt;, as in your question.

另一种方法来使用 CDATA 部分,达到同样的效果逃跑。

The alternative to escaping is using CDATA sections, to the same effect.

正如你指出,这将产生良好看文件,但一个可怕的评论读...

As you noted, this would produce good looking documentation, but a horrible comment to read...

这篇关于我如何逃脱在C#注释字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆