- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
using System;
class MyGenericClass<T> {
T ob;
public MyGenericClass(T o) {
ob = o;
}
public T getob() {
return ob;
}
public void showType() {
Console.WriteLine("Type of T is " + typeof(T));
}
}
public class Test {
public static void Main() {
MyGenericClass<int> iOb;
iOb = new MyGenericClass<int>(102);
iOb.showType();
int v = iOb.getob();
Console.WriteLine("value: " + v);
MyGenericClass<string> strOb = new MyGenericClass<string>("Generics add power.");
strOb.showType();
string str = strOb.getob();
Console.WriteLine("value: " + str);
}
}
Проверочный код 2266 не даст соврать!
прпнимайте меры!1
Думаю, уже созрел.
в c# нет шаблонов
Generic - обобщенный класс, он же шаблонный класс.
Шаблон (template) - параметр шаблонного класса.
|=>
Клаcc (generic) - не параметр (template). Действительно верно.
Обобщенный класс (Generic) == Шаблонный класс (template class).
Где здесь C++?!
хотя, в принципе, это дело терминологии. а терминология установила именно так.