Supercharge your development with unmatched features:
Access a full terminal environment, run Linux commands, and manage your project’s dependencies directly within the IDE.
Browse and interact with websites directly within the IDE. Supports real-time interaction with web content without leaving the workspace.
Manage your project files and directories effortlessly within the IDE. Create, edit, rename, move, and delete files—all in one place.
Experience seamless code editing with real-time syntax highlighting, tab support, and intelligent code suggestions for a smoother development workflow.
C# is a modern, object-oriented programming language developed by Microsoft. It is primarily used for developing Windows applications, web applications, and games using the .NET framework.
dotnet --version
in your terminal or command prompt.Let’s write our first C# program:
using System;
class Program {
static void Main() {
Console.WriteLine("Hello, World!");
}
}
Save this code as Program.cs
, and run it using the following commands:
dotnet new console -o HelloWorldApp
cd HelloWorldApp
dotnet run
C# supports various data types:
// Example:
int age = 25;
double pi = 3.14159;
char grade = 'A';
bool isStudent = true;
string name = "John Doe";
Conditional statements in C# include if
, else if
, and else
.
// Example:
int num = 10;
if (num > 0) {
Console.WriteLine("Positive number");
} else if (num == 0) {
Console.WriteLine("Zero");
} else {
Console.WriteLine("Negative number");
}
// Example:
for (int i = 0; i < 5; i++) {
Console.WriteLine(i);
}
// Example:
int count = 0;
while (count < 5) {
Console.WriteLine(count);
count++;
}
using System;
class Program {
static void Greet(string name) {
Console.WriteLine($"Hello, {name}!");
}
static void Main() {
Greet("Alice");
}
}
using System;
class Person {
public string Name { get; set; }
public int Age { get; set; }
public void Introduce() {
Console.WriteLine($"Name: {Name}, Age: {Age}");
}
}
class Program {
static void Main() {
Person person = new Person { Name = "Alice", Age = 25 };
person.Introduce();
}
}
try {
int result = 10 / 0;
} catch (DivideByZeroException ex) {
Console.WriteLine($"Error: {ex.Message}");
} finally {
Console.WriteLine("This block always executes.");
}
// Writing to a file:
using System.IO;
class Program {
static void Main() {
File.WriteAllText("example.txt", "Hello, C#!");
}
}
// Reading from a file:
using System;
using System.IO;
class Program {
static void Main() {
string content = File.ReadAllText("example.txt");
Console.WriteLine(content);
}
}
using System;
using System.Collections.Generic;
class Program {
static void Main() {
List<string> names = new List<string> { "Alice", "Bob" };
foreach (string name in names) {
Console.WriteLine(name);
}
}
}
using System;
using System.Threading;
class Program {
static void Main() {
Thread thread = new Thread(() => Console.WriteLine("Thread is running"));
thread.Start();
}
}