C#
18.C# - 매개변수가 있는 함수
Godffs
2009. 8. 6. 00:35
반응형
매개변수 == 파라미터 == 인 자 == 인수 == Parameter == Argument== 가인수 == 실인수
using System;
public class 매개변수가있는함수
{
public static void Main(string[] args)
{
Hello("안녕"); // "안녕"
Hello("방가"); // "방가"
Hello("또봐"); // "또봐"
Say("낼봐", 3);
//아래기능을 하는 함수를 설계
Calc(3, '+', 5); //8
Calc(3, '-', 5); //-2
}
public static void Calc(int num1, char gg, int num2)
{
if (gg == '+')
{
Console.WriteLine("{0} {1} {2} = {3}", num1, gg, num2,
num1 + num2);
}
else if(gg == '-')
{
Console.WriteLine("{0} {1} {2} = {3}", num1, gg, num2,
num1 - num2);
}
}
//함수를 설계 (박용준 강사님)
public static void Say(string msg, int cnt)
{
for (int i = 0; i < cnt; i++)
{
Console.WriteLine(msg); //2번째 [인자]값만큼 출력
}
}
public static void Hello(string msg)
{
Console.WriteLine(msg); //넘겨온 파라미터값을 출력
}
}
public class 매개변수가있는함수
{
public static void Main(string[] args)
{
Hello("안녕"); // "안녕"
Hello("방가"); // "방가"
Hello("또봐"); // "또봐"
Say("낼봐", 3);
//아래기능을 하는 함수를 설계
Calc(3, '+', 5); //8
Calc(3, '-', 5); //-2
}
public static void Calc(int num1, char gg, int num2)
{
if (gg == '+')
{
Console.WriteLine("{0} {1} {2} = {3}", num1, gg, num2,
num1 + num2);
}
else if(gg == '-')
{
Console.WriteLine("{0} {1} {2} = {3}", num1, gg, num2,
num1 - num2);
}
}
//함수를 설계 (박용준 강사님)
public static void Say(string msg, int cnt)
{
for (int i = 0; i < cnt; i++)
{
Console.WriteLine(msg); //2번째 [인자]값만큼 출력
}
}
public static void Hello(string msg)
{
Console.WriteLine(msg); //넘겨온 파라미터값을 출력
}
}
반응형