////메소드 예제
//using System;
//namespace Method
//{
// class Calculator
// {
// public static int Plus(int a, int b)
// {
// return a + b;
// }
// public static int Minus(int a, int b)
// {
// return a - b;
// }
// }
// class MainApp
// {
// public static void Main()
// {
// int result = Calculator.Plus(3, 4);
// Console.WriteLine(result);
// result = Calculator.Minus(5, 2);
// Console.WriteLine(result);
// }
// }
//}
////재귀호출과 리턴 예제
//using System;
//namespace Return
//{
// class Mainapp
// {
// static int Fibonacci(int n)
// {
// if (n < 2)
// return n;
// else
// return Fibonacci(n - 1) + Fibonacci(n - 2);
// }
// static void PrintProfile(string name, string phone)
// {
// if (name == “”)
// {
// Console.WriteLine(“이름을 입력해 주세요”);
// return;
// }
// Console.WriteLine(“Name:{0}, Phone:{1}”, name, phone);
// }
// static void Main(string[] args)
// {
// Console.WriteLine(“10번째 피보나치 수:{0}",Fibonacci(10));
// PrintProfile(”", “123-4567”);
// PrintProfile(“대마왕”, “456-1230”);
// }
// }
//}
////매개 변수 연습
////매소드에 들어간 값은 복사된 값이라서 본래의 값이 변하거나 하지 않는다.
//using System;
//namespace SwapByValue
//{
// class MainApp
// {
// public static void Swap(int a, int b)
// {
// int temp = b;
// b = a;
// a = temp;
// }
// static void Main()
// {
// int x = 3;
// int y = 4;
// Console.WriteLine(“x:{0},y:{1}”, x, y);
// Swap(x, y);
// Console.WriteLine(“x:{0},y:{1}”, x, y);
// }
// }
//}
//참조에 의한 매개 변수 전달
using System;
namespace SwapByRef
{
class MainApp
{
static void Swap(ref int a, ref int b)
{
int temp = b;
b = a;
a = temp;
return;
}
static void Main(string[] args)
{
int x = 3;
int y = 4;
Console.WriteLine(“x:{0}, y:{1}”, x, y);
Swap(ref x, ref y);
Console.WriteLine(“x:{0}, y:{1}”, x, y);
}
}
}