jae_coding

[유니티로 배우는 C#] 네임스페이스 본문

C#

[유니티로 배우는 C#] 네임스페이스

재코딩 2022. 7. 19. 10:49
반응형

Namespace:  누군가 만들어 놓은 클레스와 변수, 그리고 함수를 가져다 사용하는 것.

네임스페이스를 사용하는 이유는 대형 프로젝트나 협업을 하는데 함수의 명이나 변수의 이름이 곂칠 경우를 대비하기 위함이다.

using을 통하여 어떤 네임스페이스의 어떠한 변수나 함수, 그리고 네임스페이스를 언급해주고 다른 네임스페이스와 곂치지 않게 할 수 있다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Namespace.School;

namespace Namespace
{
    namespace School{
        public class Person
        {
            int student;
            
            public void SetFlag(int Value)
            {
                student = Value;
            }

            public bool IsStudent()
            {
                return student != 0;
            }
        }
    }
}

public class Unity_lecture : MonoBehaviour
{

    Person jae;
    void Start()
    {
        jae = new Person();
        jae.SetFlag(5);
        print(jae.IsStudent()); // True 출력
    }
}

강의자료: 케이디 유튜브

 

반응형
Comments