using System;
public class 메서드
{
public static void Main()
{
//input
int a = 10;
int b = 20;
int c; //초기화 하지 않음 -> 어차피 Test에 의해서 초기화 된다면..
//Test
Test(a, ref b, out c); //값만 전달
Console.WriteLine("메인 :a:{0}, b:{1}, c:{2}", a,b,c);
//TestParms,//단일
TestParams(10); //값 설정
int[] data = { 10, 20 }; TestParams(data); //배열 설정
//참조결정(가장 많이 사용방식) --> 호출과 동시에 바로 전달
TestParams(new int[] { 10, 20, 30 });
//가변 : 콤마 ,는 원하는 만큼 찍어서 전송 가능
TestParams(10, 20);
TestParams(10, 20, 30);
TestParams(10, 20, 30, 40);
}
public static void Test(int a, ref int b, out int c)
{
a = 100;
b = 200;
c = a + b; //c를 할당
//Console.WriteLine("a : {0}",a);
//Console.WriteLine("b : {0}",b);
//Console.WriteLine("c : {0}",c);
Console.WriteLine("테스트 :a:{0}, b:{1}, c:{2}", a, b, c);
}
public static void TestParams(params int[] arr)
{
foreach (var item in arr)
{
Console.WriteLine("{0}",item);
}
}
}
'.Net Project > .Net 3.5 Sp1' 카테고리의 다른 글
59장 속성(Property) (0) | 2009.08.12 |
---|---|
58장 메서드 오버로드 (0) | 2009.08.12 |
56장 JavaScript Access(자바접근) (0) | 2009.08.11 |
55장 DropDownList (0) | 2009.08.11 |
54장 Form관련 Ex-2 (0) | 2009.08.11 |