0% found this document useful (0 votes)
6 views

Methods Csharp

The document discusses different types of comments in C#, including single-line comments, multi-line comments, and how to use them. Single-line comments start with // and multi-line comments start with /* and end with */. Comments are used to explain code and prevent execution when testing alternative code.

Uploaded by

subashreenata
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Methods Csharp

The document discusses different types of comments in C#, including single-line comments, multi-line comments, and how to use them. Single-line comments start with // and multi-line comments start with /* and end with */. Comments are used to explain code and prevent execution when testing alternative code.

Uploaded by

subashreenata
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Search field


Log inSign Up Get Certified Spaces Set Goal
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C+
+ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PAND
AS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI G
O KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA
SCIENCE

C# HOMEC# IntroC# Get StartedC# SyntaxC# OutputC# CommentsC# VariablesC# Data
TypesC# Type CastingC# User InputC# OperatorsC# MathC# StringsC# BooleansC#
If...ElseC# SwitchC# While LoopC# For LoopC# Break/ContinueC# ArraysC# MethodsC#
Method ParametersC# Method OverloadingC# OOPC# Classes/ObjectsC# Class
MembersC# ConstructorsC# Access ModifiersC# PropertiesC# InheritanceC#
PolymorphismC# AbstractionC# InterfaceC# EnumsC# FilesC# ExceptionsAdd Two
NumbersC# ExamplesC# CompilerC# ExercisesC# QuizC# ServerC# Certificate

C# Comments
❮ PreviousNext ❯

C# Comments
Comments can be used to explain C# code, and to make it more readable. It
can also be used to prevent execution when testing alternative code.

Single-line Comments
Single-line comments start with two forward slashes ( //).

Any text between // and the end of the line is ignored by C# (will not be
executed).

This example uses a single-line comment before a line of code:

ExampleGet your own C# Server


// This is a comment
Console.WriteLine("Hello World!");

Try it Yourself »

This example uses a single-line comment at the end of a line of code:

Example
Console.WriteLine("Hello World!"); // This is a comment

Try it Yourself »

C# Multi-line Comments
Multi-line comments start with /* and ends with */.

Any text between /* and */ will be ignored by C#.

This example uses a multi-line comment (a comment block) to explain the


code:

Example
/* The code below will print the words Hello World

to the screen, and it is amazing */

Console.WriteLine("Hello World!");

Try it Yourself »

Single or multi-line comments?


It is up to you which you want to use. Normally, we use // for short
comments, and /* */ for longer.

C# Exercises
Test Yourself With Exercises
Exercise:
Insert the missing parts to create two types of
comments.

This is a single-line comment


This is a multi-line comment

Submit Answer »

Start the Exercise

❮ PreviousNext ❯

W3schools Pathfinder
Track your progress - it's free!
Log inSign Up
ADVERTISEMENT

COLOR PICKER

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
SPACES
UPGRADE
AD-FREE
NEWSLETTER
GET CERTIFIED
CONTACT US

Top Tutorials

HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References

HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples

HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples

Get Certified
HTML Certificate
CSS Certificate
JavaScript Certificate
Front End Certificate
SQL Certificate
Python Certificate
PHP Certificate
jQuery Certificate
Java Certificate
C++ Certificate
C# Certificate
XML Certificate
 FORUM ABOUT CLASSROOM
W3Schools is optimized for learning and training. Examples might be simplified to improve reading
and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using W3Schools, you agree to have read and
accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

You might also like