✔ C# Tutorial
✔ C# Basic
✔ C# Control Statement
✔ C# Function
✔ C# Arrays
✔ C# Object Class
✔ C# Properties
✔ C# Inheritance
✔ C# Polymorphism
✔ C# Abstraction
✔ C# Namespace
✔ C# Exception Handling
✔ C# Collections
✔ C# Misc
Comments
Comments are your programming storytellers. They don’t affect how your code runs but provide essential insights for you and others reading your code.
// This is a single-line comment
/*
This is a multi-line comment
*/
// Let’s use comments to explain our code from the previous examples:
using System;
class ExampleWithComments
{
static void Main()
{
// Loop with a break statement
for (int i = 1; i <= 10; i++)
{
if (i == 5)
{
Console.WriteLine(“Found the magic number!”);
break; // Exit the loop when i is 5
}
Console.WriteLine($”Current number: {i}”);
}
// Loop with a continue statement
for (int i = 1; i <= 5; i++)
{
if (i == 3)
{
Console.WriteLine(“Skipping the third step!”);
continue; // Skip the rest of the loop body and continue with the next iteration
}
Console.WriteLine($”Current step: {i}”);
}
// Loop with a goto statement
int counter = 0;
start:
Console.WriteLine($”Current count: {counter}”);
if (counter < 5)
{
counter++;
goto start; // Jump back to the ‘start’ label
}
}
}