Learn C# Programming
Master C# programming from basics to advanced concepts with our comprehensive tutorial series. Perfect for beginners and experienced developers.
C# Variables and Constants
What are Variables?
Variables are containers that store data values. In C#, you must declare a variable before using it.
Variable Declaration
// Syntax: dataType variableName;
int age;
string name;
double salary;
bool isActive;
Variable Initialization
// Declaration and initialization
int age = 25;
string name = "John";
double salary = 50000.50;
bool isActive = true;
// Multiple variables of same type
int x = 10, y = 20, z = 30;
Constants
Constants are variables whose values cannot be changed once assigned. Use the const keyword.
const double PI = 3.14159;
const string COMPANY_NAME = "TechCorp";
const int MAX_USERS = 1000;
// PI = 3.14; // Error! Cannot modify constant
Variable Scope
class Program
{
static int globalVar = 100; // Class-level variable
static void Main()
{
int localVar = 50; // Local variable
if (true)
{
int blockVar = 25; // Block-level variable
Console.WriteLine(globalVar); // Accessible
Console.WriteLine(localVar); // Accessible
Console.WriteLine(blockVar); // Accessible
}
// Console.WriteLine(blockVar); // Error! Out of scope
}
}
Default Values
| Data Type | Default Value |
|---|---|
int | 0 |
double | 0.0 |
bool | false |
string | null |
char | '\0' |
Important Note
Local variables must be initialized before use, while class-level variables get default values automatically.
Frequently Asked Questions
Master C# Programming with Our Comprehensive Tutorial
Our C# programming tutorial is designed to take you from a complete beginner to an advanced developer. Whether you're looking to build web applications, desktop software, or mobile apps, C# provides the foundation you need for modern software development.
Start with the basics like variables, data types, and control structures, then progress to advanced topics including object-oriented programming, LINQ, async programming, and more. Each lesson includes practical examples and exercises to reinforce your learning.
Join thousands of developers who have learned C# programming through our step-by-step tutorials. Begin your journey today and unlock the power of .NET development.