매개변수 - 출력 전용 매개변수

개발 Programming/C#|2015. 4. 22. 15:24

out 키워드


ref와 동일한 기능을 하지만 안전장치가 있음

ref로 매개변수를 넘길경우에는 메소드가 해당 매개변수에 결과를 저장하지 않아도 컴파일로는 아무런 경고를 하지 않지만

out 키워드는 매개변수를 넘길 때는 멧드가 해당 매개변수에 결과를 저장하지 않으면 컴파일러가 에러 메시지를 출력함


static void Divide(int a, int b,out int quotient ,out int remainder)

{quotient = a/b;

reaminder =a%b;

}



int a =20;

int b = 3;

int c ;

int d;


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


using System;

using System.Collections.Generic;

using System.Text;


namespace HelloWorld

{

    class HelloWorld

    {

        static void Divide(int a, int b, out int c, out int d)

        {


            c = a / b;

            d = a % b;


        }

        static void Main(string[] args)

        {

            int a = 20;

            int b = 3;

            int d;

            int c;


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

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


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




        }

       

    }

}





'개발 Programming > C#' 카테고리의 다른 글

메소드 오버로딩 - 명명된 매개변수  (0) 2015.04.22
메소드 오버로딩-가변길이 매개변수  (0) 2015.04.22
매개변수-참조에 의한 매개변수 전달  (0) 2015.04.22
var 형식  (0) 2015.04.22
Nullable 형식  (0) 2015.04.22

댓글()