You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Generics
|
|
{
|
|
/*
|
|
*
|
|
// T는 Value 타입
|
|
class MyClass<T> where T : struct
|
|
|
|
// T는 Reference 타입
|
|
class MyClass<T> where T : class
|
|
|
|
// T는 디폴트 생성자를 가져야 함
|
|
class MyClass<T> where T : new()
|
|
|
|
// T는 MyBase의 파생클래스이어야 함
|
|
class MyClass<T> where T : MyBase
|
|
|
|
// T는 IComparable 인터페이스를 가져야 함
|
|
class MyClass<T> where T : IComparable
|
|
|
|
// 좀 더 복잡한 제약들
|
|
class EmployeeList<T> where T : Employee,
|
|
IEmployee, IComparable<T>, new()
|
|
{
|
|
}
|
|
|
|
// 복수 타입 파라미터 제약
|
|
class MyClass<T, U>
|
|
where T : class
|
|
where U : struct
|
|
{
|
|
}
|
|
*
|
|
*/
|
|
class TypeContraintStack<T> where T : struct
|
|
{
|
|
T[] _elements;
|
|
int pos = 0;
|
|
|
|
public TypeContraintStack()
|
|
{
|
|
_elements = new T[100];
|
|
}
|
|
|
|
public void Push(T element)
|
|
{
|
|
_elements[++pos] = element;
|
|
}
|
|
|
|
public T Pop()
|
|
{
|
|
return _elements[pos--];
|
|
}
|
|
}
|
|
}
|
|
|