Tato značka není monitorována společností Microsoft.
int age = 25; // Celé číslo
double height = 1.75; // Desetinné číslo
char grade = 'A'; // Jediný znak
bool isStudent = true; // Logická hodnota
string name = "Alice"; // Textový řetězec
int number = 123;
string str = number.ToString(); // int na string
double pi = 3.14;
int rounded = (int)pi; // double na int (truncation)
// for
for (int i = 0; i < 5; i++)
{
Console.WriteLine(i);
}
// while
int j = 0;
while (j < 5)
{
Console.WriteLine(j);
j++;
}
// foreach (pro iteraci přes kolekce)
string[] fruits = { "jablko", "banán", "třešeň" };
foreach (string fruit in fruits)
{
Console.WriteLine(fruit);
}
int[] numbers = new int[3] { 1, 2, 3 };
numbers[0] = 10; // Změna hodnoty na indexu 0
Console.WriteLine(numbers.Length); // Délka pole
foreach (int num in numbers)
{
Console.WriteLine(num);
}
string text = "Ahoj světe!";
string lower = text.ToLower(); // "ahoj světe!"
string upper = text.ToUpper(); // "AHOJ SVĚTE!"
string substring = text.Substring(0, 4); // "Ahoj"
bool contains = text.Contains("světe"); // true
// List<T> (dynamické pole)
List<int> numbersList = new List<int> { 1, 2, 3 };
numbersList.Add(4);
numbersList.RemoveAt(0);
// Dictionary<TKey, TValue> (klíč-hodnota)
Dictionary<string, int> ages = new Dictionary<string, int>
{
{ "Alice", 25 },
{ "Bob", 30 }
};
ages["Charlie"] = 35;