在15种编程语言中添加注释的示例

{-
This is slightly long
multi line comment in Haskell
-}

Comments in JavaScript

Single Line Comment

// This is a single line comment in JavaScript

Multi-Line Comment

/* This is slightly long
multi line comment in JavaScript */

Comments in PHP

Single Line Comment

// This is a single line comment in PHP

Multi-Line Comment

/* This is slightly long
multi line comment in PHP */

Comments in Perl

Single Line Comment

# This is a single line comment in Perl

Multi-Line Comment

=begin
This is slightly long
multi line comment in Perl
=end

Comments in Swift

Single Line Comment

// This is a single line comment in Swift

Multi-Line Comment

/* This is slightly long
multi line comment in Swift */

Comments in Kotlin

Single Line Comment

// This is a single line comment in Kotlin

Multi-Line Comment

/* This is slightly long
multi line comment in Kotlin */

Comments in Rust

Single Line Comment

// This is a single line comment in Rust

Multi-Line Comment

/* This is slightly long
multi line comment in Rust */

Comments in Lua

Single Line Comment

-- This is a single line comment in Lua

Multi-Line Comment

--[[ This is slightly long
multi line comment in Lua --]]

Comments in R

Single Line Comment

# This is a single line comment in R

Multi-Line Comment

/* This is slightly long
multi line comment in R */

Comments in MATLAB

Single Line Comment

% This is a single line comment in MATLAB

Multi-Line Comment

%{
This is slightly long
multi line comment in MATLAB
%}

Comments in TypeScript

Single Line Comment

// This is a single line comment in TypeScript

Multi-Line Comment

/* This is slightly long
multi line comment in TypeScript */

Comments in Shell Scripting

Single Line Comment

# This is a single line comment in Shell Scripting

Multi-Line Comment

: '
This is slightly long
multi line comment in Shell Scripting
'

Comments in PowerShell

Single Line Comment

# This is a single line comment in PowerShell

Multi-Line Comment


Comments in HTML

Single Line Comment

<!-- This is a single line comment in HTML -->

Multi-Line Comment

<!--
This is slightly long
multi line comment in HTML
-->
{- 这是一个稍长的
多行注释在Haskell中 -}

Rust中的注释

单行注释

// 这是Rust中的单行注释

多行注释

/* 这是一个稍长的
多行注释在Rust中 */

HTML中的注释

单行注释


多行注释


CSS中的注释

单行注释

多行注释

JavaScript中的注释

单行注释

/* 这是CSS中的单行注释 */

多行注释

/* 这是一个稍长的
多行注释在CSS中 */

R中的注释

单行注释

// 这是JavaScript中的单行注释

多行注释

R不支持多行注释。

Erlang中的注释

单行注释

/* 这是一个稍长的
多行注释在JavaScript中 */

多行注释

R不支持多行注释。

PHP中的注释

单行注释

# 这是R语言中的单行注释

多行注释

% 这是Erlang中的单行注释

Perl中的注释

单行注释

// 这是PHP中的单行注释

多行注释

/* 这是一个稍长的
多行注释在PHP中 */

Kotlin中的注释

单行注释

# 这是Perl中的单行注释

多行注释

=begin 
这是一个稍长的
多行注释在Perl中
=end

结论

本教程介绍了注释的基础知识和两种常见类型:单行注释和多行注释。我还试图解释了为什么注释很有用,以及何时需要时应该编写注释。希望你学到了一些新东西!

继续探索,持续学习! 👨‍💻

类似文章