Potřebuji pomoc s Cykly a základy C#

Barbar 30 Reputační body
2025-04-28T20:22:07.49+00:00

Například příklady while, for, do while cyklu, proměnné, funkce, procedury a tak dále...

Komunitní centrum | Není monitorováno
Počet komentářů: 0 Žádné komentáře

1 odpověď

Seřadit podle: Nejstarší
  1. Karel Daniel 0 Reputační body
    2025-04-28T20:23:49.2033333+00:00

    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;

    Byla tato odpověď užitečná?

    Počet komentářů: 0 Žádné komentáře

Vaše odpověď

Odpovědi můžou být autorem otázky označeny jako „Přijaté“ a moderátory jako „Doporučené“, což uživatelům pomůže zjistit, že odpověď vyřešila problém autora.