반응형
Recent Posts
Recent Comments
«   2024/05   »
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 31
Tags
more
Archives
Today
Total
관리 메뉴

Real Vectorism. 훨씬 더 입체적으로...

생성자 오버로딩 본문

C# (based by Unity)

생성자 오버로딩

grast 2022. 7. 5. 08:53
반응형

자바

class Example {
    private int idx;
    private String username;
    private String password;
    
    // 아래로 내려가는 오버로딩
    public Example() {
        this(0);
    }
    public Example(int idx) {
        this(idx, null);
    }
    public Example(int idx, String username) {
        this(idx, username, null);
    }
    public Example(int idx, String username, String password) {
        this.idx = idx;
        this.username = username;
        this.password = password;
        
        // 생성자 공통기능 영역
    }
}

씨샵

public class Example {
    private int idx;
    private string username;
    private string password;
    
    // 위로 올라가는 오버로딩
    public Example() {
        // 생성자 공통기능 영역
    }
    public Example(int idx) : this() {
        this.idx = idx;
    }
    public Example(int idx, string username) : this(idx) {
        this.username = username;
    }
    public Example(int idx, string username, string password) : this(idx, username) {
        this.password = password;
    }
}
반응형

'C# (based by Unity)' 카테고리의 다른 글

또다른 깨달음  (0) 2023.06.03
유니티 비트 쪼개기  (1) 2022.12.01
잘은 모르겠지만  (0) 2021.08.17
슈팅패러다임2 업데이트  (0) 2021.05.18
Shooting Paradigm 2 플레이스토어 출시  (0) 2020.11.24
Comments