codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🔷

C# Programming

2 / 60 topics
1Getting Started with C#2C# Syntax3Variables in C#4Data Types in C#5Operators in C#
Tutorials/C# Programming/C# Syntax
🔷C# Programming

C# Syntax

Updated 2026-05-15
10 min read

C# Syntax

Introduction

Welcome to your journey into the world of C#. This tutorial is designed to help you understand the fundamental syntax and structure of the language. Whether you're a beginner or an intermediate developer, mastering C# syntax will provide a solid foundation for building robust applications.

C# (pronounced "C Sharp") is a modern, object-oriented programming language developed by Microsoft as part of its .NET framework. It's widely used for developing desktop applications, web services, and enterprise software. Understanding the core syntax is crucial to writing effective C# code.

Concept

In this section, we'll cover some basic concepts that form the core of C# syntax:

  1. Statements: Instructions that perform a specific task.
  2. Comments: Notes in the code that are ignored by the compiler.
  3. Variables: Storage locations for data.
  4. Data Types: Classifications of variables that define their size and behavior.
  5. Operators: Symbols used to perform operations on variables or values.

Statements

Statements are the building blocks of C# programs. They end with a semicolon (;). For example:

csharp
1int number = 10;

This statement declares an integer variable named number and assigns it the value 10.

Comments

Comments are used to explain your code, making it easier for others (and yourself) to understand. C# supports two types of comments:

  • Single-line comments: Start with //.
  • Multi-line comments: Enclosed within /* */.
csharp
1// This is a single-line comment
2
3/*
4This is
5a multi-line
6comment.
7*/

Variables

Variables store data that can be manipulated during the execution of a program. In C#, you must declare variables before using them, specifying their data type.

csharp
1int age = 25;
2string name = "John Doe";

In this example, age is an integer variable and name is a string variable.

Data Types

C# supports various data types, including:

  • Primitive Types: Basic data types like int, float, char, etc.
  • Reference Types: More complex data types like classes, interfaces, arrays, etc.
csharp
1int integer = 10;
2double floatingPoint = 3.14;
3char character = 'A';
4bool boolean = true;

Operators

Operators are used to perform operations on variables or values. C# supports arithmetic, comparison, logical, and assignment operators.

csharp
1int a = 5;
2int b = 3;
3
4int sum = a + b; // Addition
5bool isEqual = a == b; // Comparison

Examples

Let's put these concepts together in some practical examples.

Example 1: Basic Program

Here's a simple C# program that prints "Hello, World!" to the console:

csharp
1using System;
2
3class Program
4{
5 static void Main()
6 {
7 Console.WriteLine("Hello, World!");
8 }
9}

Example 2: Variable Manipulation

This example demonstrates how to declare variables and perform operations on them:

csharp
1using System;
2
3class Program
4{
5 static void Main()
6 {
7 int num1 = 10;
8 int num2 = 5;
9
10 int sum = num1 + num2;
11 Console.WriteLine("Sum: " + sum);
12
13 int difference = num1 - num2;
14 Console.WriteLine("Difference: " + difference);
15 }
16}

Example 3: Conditional Statements

Conditional statements allow you to execute code based on certain conditions:

csharp
1using System;
2
3class Program
4{
5 static void Main()
6 {
7 int number = 10;
8
9 if (number > 5)
10 {
11 Console.WriteLine("Number is greater than 5");
12 }
13 else
14 {
15 Console.WriteLine("Number is not greater than 5");
16 }
17 }
18}

What's Next?

Now that you've learned about the core syntax of C#, it's time to dive deeper into variables. In the next section, we'll explore different types of variables, how to declare them, and their usage in C# programs.

Stay tuned for more tutorials on codingstuff.io!


PreviousGetting Started with C#Next Variables in C#

Recommended Gear

Getting Started with C#Variables in C#