오늘의 C# 공부 : 매개변수

////출력 전용 매개 변수
//// out을 입력하면 값을 메소드에서 값을 반드시 넣어야 한다.
//// out을 입력하면 메소드에서 값을 읽을 수 없고 출력만 할 수 있다.
//using System;

//namespace UsingOut
//{
//    class MainApp
//    {
//        static void Divide(int a, int b, out int quotient, out int remainder)
//        {
//            quotient = a/b;
//            remainder = a%b;
//        }

//        static void Main(string[] args)
//        {
//            int a = 20;
//            int b = 3;
//            int c;
//            int d;

//            Divide(a,b,out c, out d);

//            Console.WriteLine(“a:{0},b:{1}, a/b:{2}, a%b{3}",a,b,c,d);
//        }
//    }
//}

////메소드 오버로딩
//// 같은 이름의 메소드로 여러 개의 연산을 만들 수 있다.
//using System;

//namespace HelloWorld
//{
//    class MainApp
//    {
//        static int Plus (int a,int b)
//        {
//            Console.WriteLine(“Calling int Plus(int,int)…”);
//            return a + b;
//        }

//        static int Plus(int a, int b, int c)
//        {
//            Console.WriteLine(“Calling int Plus (int, int,int)…”);
//            return a + b + c;
//        }

//        static double Plus(double a, double b)
//        {
//            Console.WriteLine(“Calling double Plus (double, double)….”);
//            return a + b;
//        }

//        static double Plus(int a, double b)
//        {
//            Console.WriteLine(“Calling douvle Plus(int,double)….”);
//            return a + b;
//        }

//        static void Main(string[] args)
//        {
//            Console.WriteLine(Plus(1, 2));
//            Console.WriteLine(Plus(1, 2, 3));
//            Console.WriteLine(Plus(1.0, 2.4));
//            Console.WriteLine(Plus(1, 2.4));
//        }
//    }
//}

//////가변길이 매개 변수

////using System;

////namespace UsingParams
////{
////    class MainApp
////    {
////        static int Sum(params int[] args)
////        {
////            Console.Write(“Summing….”);
////            int sum = 0;

////            for (int i = 0; i < args.Length; i++)
////            {
////                if (i > 0)
////                    Console.Write(”, “);

////                Console.Write(args[i]);
////                sum += args[i];
////            }

////            Console.WriteLine();
////            return sum;
////        }

////        static void Main(string[] args)
////        {
////            int sum =  Sum(1,2,3,4,5,6,7,8,9,10);
////            Console.WriteLine(“Sum :{0}",sum);
////        }
////    }
////}

////명명된 매개 변수
//using System;

//namespace NameParameter
//{
//    class HelloWorld
//    {
//        static void PrintProfile(string name, string phone)
//        {
//            Console.WriteLine(“Name : {0}, phone : {1}”, name, phone);
//        }

//        static void Main()
//        {
//            PrintProfile(name: “박찬호”, phone: “010-123-4567”);
//            PrintProfile(phone: “010-000-0000”, name: “박지성”);
//            PrintProfile(“박세리”, “010-111-1111”);
//            PrintProfile(“대마왕”, phone: “010-852-9631”);
//        }
//    }
//}

////선택적 매개 변수
//using System;

//namespace OpionalParameter
//{
//    class HelloWorld
//    {
//        static void PrintProfile(string name, string phone = “”)
//        {
//            Console.WriteLine(“Name:{0},Phone:{1}”, name, phone);
//        }

//        static void Main(string[] args)
//        {
//            PrintProfile(“태연”);
//            PrintProfile(“윤아”, “010-123-4567”);
//            PrintProfile(name: “유리”);
//            PrintProfile(name: “서현”, phone: “010-456-7894”);           
//        }
//    }
//}

Hugo로 만듦
JimmyStack 테마 사용 중