C# 네임스페이스와 열거형
2019. 9. 3. 08:59ㆍPL/C++
C#에서의 네임스페이스는 기능의 이름 중복을 피하기 위한 공간으로써 C++에서의 네임스페이스와 기능이 유사하다. 네임스페이스를 이용해 동일한 이름의 클래스를 분리된 공간에서 사용할 수 있다. enum 열거형 변수와 C에서와 유사하게 쓸 수 있으며 특별한 번호 할당이 없으면, 0부터 시작한다
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Example1 | |
{ | |
class Example | |
{ | |
public static string data = "Example"; | |
} | |
} | |
namespace Example2 | |
{ | |
class Example | |
{ | |
public static string data = "Example"; | |
} | |
} | |
namespace introCsharp | |
{ | |
class Program | |
{ | |
enum Color { BLACK, BLUE, RED, GREEN }; | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello world"); | |
Console.WriteLine(Example1.Example.data); | |
Console.WriteLine(Example2.Example.data); | |
// Console.ReadLine(); // 사용자 엔터 대기 | |
Color color = Color.BLACK; | |
if(color == Color.BLACK) | |
{ | |
Console.WriteLine("검은색입니다"); | |
} | |
else | |
{ | |
Console.WriteLine("검은색이 아닙니다"); | |
} | |
Console.WriteLine((int)Color.BLACK); | |
Console.WriteLine((int)Color.BLUE); | |
Console.WriteLine((int)Color.RED); | |
Console.WriteLine((int)Color.GREEN); | |
} | |
} | |
} |

'PL > C++' 카테고리의 다른 글
C# 스레드 안에서 타이머 동작시키기 (0) | 2019.09.05 |
---|---|
system("cls") 떨림 현상 줄이는 방법 (0) | 2019.09.03 |
네트워크 오목 게임 구현하기 (0) | 2019.09.02 |
C++에서의 string token (0) | 2019.09.02 |
memset과 ZeroMemory (0) | 2019.09.02 |