Universal Code Snippet
using System;
class Program {
static void Main() {
Console.WriteLine("Hello, World!");
}
}using System;
class Program {
static void Main() {
Console.Write("Enter your name: ");
string name = Console.ReadLine();
Console.WriteLine("Hello, " + name + "!");
}
}using System;
class Program {
static void Main() {
int age = 20;
if (age >= 18) {
Console.WriteLine("You are an adult.");
} else {
Console.WriteLine("You are a minor.");
}
}
}using System;
class Program {
static void Main() {
Console.WriteLine("For loop:");
for (int i = 1; i <= 5; i++) {
Console.Write(i + " ");
}
Console.WriteLine();
Console.WriteLine("While loop:");
int j = 1;
while (j <= 5) {
Console.Write(j + " ");
j++;
}
Console.WriteLine();
}
}using System;
class Program {
static int Add(int a, int b) {
return a + b;
}
static void Main() {
Console.WriteLine("Sum: " + Add(10, 20));
}
}using System;
class Program {
static void Main() {
int[] numbers = {10, 20, 30, 40, 50};
for (int i = 0; i < numbers.Length; i++) {
Console.WriteLine("Element " + i + ": " + numbers[i]);
}
}
}using System;
class Program {
static void Main() {
string str1 = "Hello";
string str2 = " World";
Console.WriteLine("Length: " + str1.Length);
string combined = str1 + str2;
Console.WriteLine("Concatenated: " + combined);
string str3 = combined;
Console.WriteLine("Copied: " + str3);
}
}using System;
class Program {
static void Main() {
float a = 15.0f, b = 4.0f;
Console.WriteLine("Add: " + (a + b));
Console.WriteLine("Subtract: " + (a - b));
Console.WriteLine("Multiply: " + (a * b));
Console.WriteLine("Divide: " + (a / b));
}
}