gnu

블로그 이미지
by 군우

TAG CLOUD

  • Total hit
  • Today hit
  • Yesterday hit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int x1 = 10;
            int x2; 
            Cal(ref x1);
            Cal2(out x2); //out: 초기화하지않고 사용가능.
            Console.WriteLine("Cal: {0}", x1);
            Console.WriteLine("Cal: {0}", x2);
        }
        static void Cal(ref int x){
            x = 10000;
        }
        static void Cal2(out int x)
        {
            x = 10000;
        }
    }
}
cs


ref는  초기화 해야만 사용할 수 있는 참조 타입이고

out은 초기화하지 않아도 사용할 수 잇는 타입임 .


일반적으로 out을 사용함.


주소값을 넘길 때 사용할 수 있다.

'C# > C# Concept' 카테고리의 다른 글

[C#] 오버로딩  (0) 2018.04.05
[C#] Const 상수 사용법  (0) 2018.03.29
[C#] 인터페이스 다중상속  (0) 2018.03.22
[C#] 다형성 (polymorphism)  (0) 2018.03.22
[C#] 파생 클래스  (0) 2018.03.22
AND

ARTICLE CATEGORY

분류 전체보기 (197)
C (0)
HTML (7)
C# (88)
Python (27)
IT (0)
Android (2)
Java (65)
Study (5)
JavaScript (1)
JSP (2)

RECENT ARTICLE

RECENT COMMENT

CALENDAR

«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

ARCHIVE

LINK