mirror of
https://github.com/pepaskopec-blip/Graduately.git
synced 2026-10-27 15:14:35 +00:00
Add a C# course with a side-by-side code runner.
Each lesson explains a topic and runs the edited program next to the text through the local .NET SDK. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
6662eb185e
commit
333085ee53
86 changed files with 2482 additions and 5 deletions
39
content/programovani/4-rocnik/03-slovnik.md
Normal file
39
content/programovani/4-rocnik/03-slovnik.md
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
---
|
||||
id: cs-4-slovnik
|
||||
nazev: Slovník
|
||||
popis: Hodnota pod klíčem.
|
||||
---
|
||||
|
||||
# Výklad
|
||||
|
||||
## Klíč
|
||||
*jednou*
|
||||
|
||||
- Dictionary<string, int> má klíč text a hodnotu číslo.
|
||||
- znamky["Anna"] = 1 uloží nebo přepíše.
|
||||
- Stejný klíč je v slovníku jen jednou.
|
||||
|
||||
> Tip: Pole je podle čísla. Slovník je podle jména, které si zvolíte.
|
||||
|
||||
## Čtení
|
||||
*ContainsKey*
|
||||
|
||||
- Čtení chybějícího klíče spadne.
|
||||
- ContainsKey napřed zjistí, jestli klíč je.
|
||||
- foreach projde dvojice Key a Value.
|
||||
|
||||
> Tip: Zeptejte se na jméno, které v slovníku není, až po ContainsKey.
|
||||
|
||||
# Kód
|
||||
|
||||
```
|
||||
Dictionary<string, int> znamky = new Dictionary<string, int>();
|
||||
znamky["Anna"] = 1;
|
||||
znamky["Eva"] = 2;
|
||||
znamky["Anna"] = 3;
|
||||
if (znamky.ContainsKey("Eva"))
|
||||
{
|
||||
Console.WriteLine(znamky["Eva"]);
|
||||
}
|
||||
Console.WriteLine(znamky["Anna"]);
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue