using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study11
{
internal class App
{
public App()
{
//일반화 메서드
int[] arr0 = { 1, 2, 3 }; //배열 생성
int[] arr1 = new int[3]; //{0, 0, 0}
CopyArray(arr0, arr1); //배열을 매게변수로 사용
string[] arr2 = { "홍길동", "임꺽정", "장길산" };
string[] arr3 = new string[3];
CopyArray(arr2, arr3);
Hero[] arr4 = { new Hero(), new Hero(), new Hero() }; //인스턴스를 인덱스로 사용
Hero[] arr5 = new Hero[3];
CopyArray(arr4, arr5);
CopyArray<int>(arr0, arr1); //<type>
CopyArray<string>(arr2, arr3);
CopyArray<Hero>(arr4, arr5);
}
void CopyArray<T>(T[] a, T[] b) //<T> 일반화 메서드 생성 , <T> 해당 타입으로 정의된다. 익숙해지면 정말 편하겠다
{
for (int i = 0; i < a.Length; i++)
{
b[i] = a[i];
}
}
//Method OverLoading
void CopyArray(Hero[] a, Hero[] b) //메서드 오버로드 =>같은 메서드에 다른 매개변수를 사용한다
{
for (int i = 0; i < a.Length; i++)
{
b[i] = a[i];
}
}
//Method OverLoading
void CopyArray(string[] a, string[] b) //메서드 오버로드 =>같은 메서드에 다른 매개변수를 사용한다
{
for (int i = 0; i < a.Length; i++)
{
b[i] = a[i];
}
}
void CopyArray(int[] a, int[] b) //메서드 오버로드 =>같은 메서드에 다른 매개변수를 사용한다
{
for (int i = 0; i < a.Length; i++)
{
b[i] = a[i];
}
}
}
}