如何评论代码java / c#

时间:2013-06-14 16:17:52

标签: c# java commenting

说我是否有代码

  static private String[][] getRssData(String channel)
 {
     //Code here...
 }

有没有办法可以在悬停时查看功能说明? 即添加

 //this is Using to get the RssData

我打算用c#和java编码

来做这件事

5 个答案:

答案 0 :(得分:6)

在用于C#的Visual Studio IDE中,您可以使用XML Documentation

///<summary>
///This is used to get the RSS data
///</summary>
///<param name="channel">The channel</param>
///<returns>The RSS data</returns>
private static string[][] GetRssData(string channel)
{
    //...
}

您可以使用Android Studio中的[Javadoc]插件(http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html)在Java中执行相同操作:

/**
* This is used to get the RSS data 
* @param channel The channel
* @return The RSS data
*/
static String[][] getRssData(String channel)
{
    //...
}

答案 1 :(得分:2)

在方法上面的c#type ///中,将自动生成sumarry stub

答案 2 :(得分:2)

在C#中你可以这样做:

/// <summary>
/// this is Using to get the RssData
/// </summary>
static private string[][] GetRssData(string channel)
{
    //Code here...
}

More about <summary>

在Java中:

/**
* this is Using to get the RssData
*/
static private string[][] getRssData(String channel)
{
    //Code here...
}

答案 3 :(得分:2)

在Java中,Javadoc注释是编写文档注释的首选方式。

刚刚放

/**
 * Your comments go here.
 */

在方法标题之前,您的IDE可能会显示以html格式化的注释。

此外,您可以使用javadoc工具为您的代码生成html文档,就像API一样。

以下是撰写优秀javadoc评论的指南:http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html

答案 4 :(得分:1)

  

有没有办法可以在悬停时查看功能说明?

这是您正在使用的IDE的功能,而不是语言。如果你在(比如)记事本中查看你的源代码,你将无法获得悬停文本。

但是(例如)当您将鼠标悬停在源代码中的方法名称上时,Eclipse IDE可以在弹出窗口中格式化并显示方法的javadoc注释。 (您不需要将javadoc后处理为HTML以实现此目的.Eclipse即时从源代码中提取相关注释。)