如何写评论 [英] How To write comments
问题描述
您好我有50页的代码,我应该给它写评论...
你能告诉我最好的方法。我需要你写一个样例...
注释应该包含几乎所有的东西(类,构造函数,属性,方法,事件,函数)
Hi I have like 50 pages of code that I should write comments to it ... Can you guys show me the best way. I meant I need you to write me a sample ... the comments should contain nearly everything (classes, constructors, attribute, methods, events, functions)
推荐答案
不要评论什么是显而易见的
Don't comment what is obvious like
//The width of the line is 2
lineWidth = 2;
或
//Clones the snapshot
tempDraw = (Bitmap)snapshot.Clone();
可能有一个好主意来解释为什么某个代码行存在。例如解释为什么
There might be a good idea to explain WHY a certain code line is there. For example explain why
panel1.Invalidate();
需要无效。
基本思想是:添加额外的信息与评论,并使用它们的解释,不要造成冗余和重复。
The basic idea is: add extra information with comments and use them for explanations, don't create redundancy and duplication.
编辑:
您可能还想解释为什么工具栏中的每个项目都需要在这里取消选中:
You might also want to explain why each item in the toolbar needs to be unchecked here:
private void toolStripButton1_Click(object sender, EventArgs e)
{
foreach (ToolStripButton btn in toolStrip1.Items)
{
btn.Checked = false;
}
...
}
一个好的注释会是这样:
A good comment would be something like:
private void toolStripButton1_Click(object sender, EventArgs e)
{
//Deselect all previously applied filters because the user clicked "disable all",
//which removes the effects of all filters and we want to show this the the user
foreach (ToolStripButton btn in toolStrip1.Items)
{
btn.Checked = false;
}
...
}
这篇关于如何写评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!