Yang.공부방

Class : 사용자정의 데이터타입, 참조형식이다.

struct는 값형식(복사시 값들이 복사 된다), class는 참조형식(복사시 참조만 복사 된다.) 


조형식의 변수 선언시 new연산자를 사용하여 클래스의 인스턴스를 명시적으로 만들 수 있다.

접근지정자 : public(어디서든지 접근 가능)

private(동일 클래스안에서만 접근 가능)

protected(동일 클래스의 코드, 파생클래스의 코드에서만 접근가능)

internal(동일한 어셈블리의 코드에서는 형식이나 멤버에 액세스할 수 있지만 다른 어셈블리의 코드에서는 액세스할 수 없습니다.) <-???

protected internal(동일한 어셈블리의 코드 또는 다른 어셈블리의 파생 클래스에서 형식이나 멤버에 액세스할 수 있습니다.)<-????

인스턴스 : 프로그램 실행 시 메모리에 할당하는 변수 또는 함수 (객체,개체라고도 한다) , 인스턴스가 객체보다 큰 범위를 포함

객체와 인스턴스 차이 : 객체(Object)는 구현할 대상, 클래스(Class)는 객체를 구현하기 위한 설계도, 인스턴스(Instance)는 설계도에 따라 구현된 실체



class 참조 : https://docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/classes-and-structs/classes

class 참조 : http://charlie0301.blogspot.com/2016/04/c-class.html

접근지정자 참조 : http://blog.naver.com/PostView.nhn?blogId=skyarro&logNo=120095630095

인스턴스 생성자 참조 : https://docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/classes-and-structs/instance-constructors

인스턴스 참조 : http://jungwoo5394.blogspot.com/2015/08/instance.html

객체와 인스턴스 차이 참조 : https://cerulean85.tistory.com/149     또는   https://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/



new : 개체를 만들고 생성자를 호출

개체를 만들 때 사용 작성 법 : new키워드 뒤에 클래스 이름과 ();를 넣는다.( 개체생성 및 생성자 호출)

생성자 : class , struct를 만들 때 마다 해당 생성자를 호출


new 참조 : https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/keywords/new-operator


dot(.)연산자 : 구조체버에 액세스에 사용(접근 할 수 있게 해준다.)

네임스페이스 또는 형식의 멤버에 액세스할 수 있다.

namespace : 파일들을 관리하기 위한 폴더?  함수 이름이 똑같을 시에 충돌을 방지하기 위한 name



namespace 참조 : https://docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/namespaces/#namespaces-overview

namespace 참조 : https://leehosung3576.tistory.com/20

namespace 참조 : https://baseofmint.tistory.com/1

dot연산자 참조 : https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/operators/member-access-operator



형식변환


암시적 변환 : 형식이 안전하고 데이터가 손실되지 않으므로 특수 구문이 필요없다. (파생클래스 -> 기본클래스로 변환)

작은범위 -> 큰범위 변환 ex) int 형 -> short형 변환, float형 -> int형 변환, 숫자형 -> char형 변환



명시적 변환(캐스트변환) : 캐스트연산자 필요 (int),(double) 과 같이 괄호안에 변환 할 타입을 밝힌다.



사용자 정의 변환



도우미클래스를 사용한 변환



명시적변환 참조2 : http://soen.kr/book/dotnet/book/3-4-2.htm


멤버변수 : 클래스 안에 정의되어있는 변수 , 어떤 메소드에도 포함되어 있지 않는 변수

특징 : 클래스 내부 어디서든 사용가능, 값이 사라지지 않는다.



지역변수메소드 안에 선언된 변수(로컬변수라고도 불린다)

특징 : 선언된 메소드 안에서만 사용이 가능, 한번 실행이 되면 초기화



클래스 객체 생성 및 출력 코드 노트에 적고 읽기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ClassEx
{
    
    class EX1
    {
        public string name = "양재준";
        public EX1()
        {
            this.name = null;
        }
    }
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ClassEx
{
    
    class EX1
    {
        public string name = "양재준";
        public EX1()
        {
            this.name = null;
        }
    }
}
cs


null 키워드 : 참조형식 변수의 기본값