C# 네임스페이스와 열거형

2019. 9. 3. 08:59PL/C++

C#에서의 네임스페이스는 기능의 이름 중복을 피하기 위한 공간으로써 C++에서의 네임스페이스와 기능이 유사하다. 네임스페이스를 이용해 동일한 이름의 클래스를 분리된 공간에서 사용할 수 있다. enum 열거형 변수와 C에서와 유사하게 쓸 수 있으며 특별한 번호 할당이 없으면, 0부터 시작한다

 

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);
}
}
}
view raw cshap01.cs hosted with ❤ by GitHub

 

 

'PL > C++' 카테고리의 다른 글