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
37
content/programovani/4-rocnik/06-generika.md
Normal file
37
content/programovani/4-rocnik/06-generika.md
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
id: cs-4-generika
|
||||
nazev: Generika
|
||||
popis: Jedna metoda pro víc typů.
|
||||
---
|
||||
|
||||
# Výklad
|
||||
|
||||
## T
|
||||
*typový parametr*
|
||||
|
||||
- static void Vypis<T>(T hodnota) přijme int i string.
|
||||
- T se doplní při volání podle argumentu.
|
||||
- Jedna metoda tak nenutí kopírovat kód pro každý typ.
|
||||
|
||||
> Tip: Když metoda s T má umět jen porovnávat, T se omezí. Tady stačí výpis.
|
||||
|
||||
## List
|
||||
*už ho znáte*
|
||||
|
||||
- List<string> je generická třída. string je dosazený T.
|
||||
- Stejný List<int> drží čísla a metody jsou stejné.
|
||||
- Generika hlídá typ. Do List<int> string nedáte.
|
||||
|
||||
> Tip: Zavolejte Vypis s číslem i s textem.
|
||||
|
||||
# Kód
|
||||
|
||||
```
|
||||
Vypis(7);
|
||||
Vypis("ahoj");
|
||||
|
||||
static void Vypis<T>(T hodnota)
|
||||
{
|
||||
Console.WriteLine(hodnota);
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue