C# Comments - c# - c# tutorial - c# net




C# Comment

C# Comment

What are the types of comments in C# ?

  • The C# comments are statements that are not executed by the compiler.
  • The comments in C# programming can be used to provide explanation of the code, variable, method or class.
  • By the help of comments, you can hide the program code also.
  • A comment contains information that a programmer wants to add to describe the program.
  • Comments are marked with special characters that indicate that they should be ignored by the compiler.
  • They have no effect on the final software.
  • There are two types of comments in C#.
    • Single Line comment
    • Multi Line comment
 comment in C#

comment in C#

C# Single Line Comment

  • The simplest form of comment in C# is the single line comment.
  • The line is started with a double forward slash, (//).
  • Any text or code following the double slash is ignored during compilation.
  • Let's see an example of single line comment in C#.
using System;
public class CommentExample
    {
public static void Main(string[] args)
        {
int x = 10;//Here, x is a variable  
Console.WriteLine(x);
        } 
    }

C# examples - Output :

10

C# Multi Line Comment

  • The C# multi line comment is used to comment multiple lines of code.
  • It is surrounded by slash and asterisk (/* ..... */).
  • It is useful for commenting out large blocks of code.
  • Let's see an example of multi line comment in C#.
using System;	
public class CommentExample
    {
public static void Main(string[] args)
        {
            /* Let's declare and 
		print variable in C#. */ 
	int x=20;
Console.WriteLine(x);
        }
    }

C# examples - Output :

20

Related Searches to C# Comments

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×