초기 커밋.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,58 @@
|
||||
class MyStack<T>
|
||||
{
|
||||
T[] _elements;
|
||||
int pos = 0;
|
||||
|
||||
public MyStack()
|
||||
{
|
||||
_elements = new T[100];
|
||||
}
|
||||
|
||||
public void Push(T element)
|
||||
{
|
||||
_elements[++pos] = element;
|
||||
}
|
||||
|
||||
public T Pop()
|
||||
{
|
||||
return _elements[pos--];
|
||||
}
|
||||
}
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
|
||||
// 두 개의 서로 다른 타입을 갖는 스택 객체를 생성
|
||||
MyStack<int> numberStack = new MyStack<int>();
|
||||
MyStack<string> nameStack = new MyStack<string>();
|
||||
}
|
||||
}
|
||||
|
||||
// T는 Value 타입
|
||||
class MyClassS<T> where T : struct { }
|
||||
|
||||
// T는 Reference 타입
|
||||
class MyClassC<T> where T : class { }
|
||||
|
||||
// T는 디폴트 생성자를 가져야 함
|
||||
class MyClassD<T> where T : new() { }
|
||||
|
||||
// T는 EventArgs의 파생클래스이어야 함
|
||||
class MyClassMyBase<T> where T : EventArgs { }
|
||||
|
||||
// T는 IComparable 인터페이스를 가져야 함
|
||||
class MyClass<T> where T : IComparable { }
|
||||
|
||||
// 좀 더 복잡한 제약들
|
||||
class EmployeeList<T> where T : EventArgs, IDisposable, IComparable<T>, new()
|
||||
{
|
||||
}
|
||||
|
||||
// 복수 타입 파라미터 제약
|
||||
class MyClass<T, U>
|
||||
where T : class
|
||||
where U : struct
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user