제네릭(generic)이란? -------------------------------------------------------------------------------------------------
제네릭이란?
// Declare the generic class.
public class GenericList<T> -> 템플릿과 비슷한 문법이지만 훨씬 간단하게 사용이 가능하다.
{
public void Add(T input)
{
Console.WriteLine(input);
Console.WriteLine(input.GetType());
}
}
class TestGenericList
{
private class ExampleClass { }
static void Main()
{
// Declare a list of type int.
GenericList<int> list1 = new GenericList<int>();
list1.Add(1); -> 지정한 형으로 넣을수 있다.
// Declare a list of type string.
GenericList<string> list2 = new GenericList<string>();
list2.Add("zz"); -> 지정한 형으로 넣을수 있다.
// Declare a list of type ExampleClass.
GenericList<ExampleClass> list3 = new GenericList<ExampleClass>();
list3.Add(new ExampleClass()); -> 지정한 형으로 넣을수 있다.
}
}
함수와 변수의 종류? -------------------------------------------------------------------------------------------------
namespace GlobalMember
{
public class Global
{
public static string global = "";
}
public class Usecase
{
public static void Main()
{
Global.global = "Hello";
Console.WriteLine (Global.global.ToString()); -> 출력 결과 Hello.
}
}
}
이런 식이다. 마찬가지로 클래스 이므로 속성등을 지정해 주는것도 가능하다. 유용하게 사용해보자.
'게임개발공부 > C#공부' 카테고리의 다른 글
C#에서 const (0) | 2013.12.29 |
---|---|
c#에서의 다형성 (0) | 2013.12.27 |
속성(property) (0) | 2013.12.27 |
override 문법의 직관화 (0) | 2013.12.20 |
참조형 함수인자. 확장 메서드. (0) | 2013.12.19 |