[英]how to add comments referring to a piece of code or #region in visual studio
我有一段代码,比如说第 2000 行的一个 if 条件。这段代码完全依赖于第 1000 行另一段代码中的 output。所以我需要在第 2000 行写注释以引用第 1000 行。
那么,我如何在第 2000 行写一个 cref 类型的注释,以便单击并导航到第 1000 行?
例如。,
ln 1000
int count = 100;
count += some-condition;
ln 2000
if (count-condition)
{
statement;//this condition depends on the piece of code on **<cref reference>ln 1000 or region**
}
如果你的方法变得太大,你应该开始考虑重构,创建更小的方法。
就像我今天一样,你不能用正常的评论来做到这一点。
当我需要完成这样的任务时,我使用 XML 方法注释。
/// <summary>
/// Does something
/// </summary>
/// <returns>Some integer </returns>
public int foo()
{
return 10;
}
/// <summary>
/// Does something
/// </summary>
/// <param name="value">Some int taken from <seealso cref="foo"/> method</param>
public void bar(int value)
{
}
如果您在 bar 方法中按 F12,您将看到注释。 当您在<seealso cref="foo"/>
内的“foo”中按 F12 时,您将 go 直接进入“foo”方法定义。
另外:如果你重命名“foo”方法,它也会更新文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.