방법: My 네임스페이스 사용(C# 프로그래밍 가이드)

Microsoft.VisualBasic.MyServices 네임스페이스(Visual Basic의 경우 My)를 사용하여 많은 .NET Framework 클래스에 간편하고 직관적으로 액세스할 수 있으며, 이를 통해 컴퓨터, 응용 프로그램, 설정, 리소스 등과 상호 작용하는 코드를 작성할 수 있습니다. MyServices 네임스페이스는 원래 Visual Basic에서 사용하도록 디자인되었지만 C# 응용 프로그램에서도 사용할 수 있습니다.

Visual Basic에서 MyServices 네임스페이스를 사용하는 방법에 대한 자세한 내용은 My를 사용한 개발(Visual Basic)을 참조하십시오.

참조 추가

솔루션에서 MyServices 클래스를 사용하려면 우선 Visual Basic 라이브러리에 대한 참조를 추가해야 합니다.

Visual Basic 라이브러리에 대한 참조를 추가하려면

  1. 솔루션 탐색기에서 참조 노드를 마우스 오른쪽 단추로 클릭하고 참조 추가를 선택합니다.

  2. 참조 대화 상자가 표시되면 목록을 아래로 스크롤하여 Microsoft.VisualBasic.dll을 선택합니다.

    또한 프로그램 시작 부분의 using 섹션에 다음 줄을 추가해야 합니다.

    using Microsoft.VisualBasic.Devices;
    

예제

다음 예제에서는 MyServices 네임스페이스에 있는 여러 정적 메서드를 호출합니다. 이 코드를 컴파일하려면 프로젝트에 Microsoft.VisualBasic.DLL에 대한 참조를 추가해야 합니다.

using System;
using Microsoft.VisualBasic.Devices;

class TestMyServices
{
    static void Main()
    {
        // Play a sound with the Audio class:
        Audio myAudio = new Audio();
        Console.WriteLine("Playing sound...");
        myAudio.Play(@"c:\WINDOWS\Media\chimes.wav");

        // Display time information with the Clock class:
        Clock myClock = new Clock();
        Console.Write("Current day of the week: ");
        Console.WriteLine(myClock.LocalTime.DayOfWeek);
        Console.Write("Current date and time: ");
        Console.WriteLine(myClock.LocalTime);

        // Display machine information with the Computer class:
        Computer myComputer = new Computer();
        Console.WriteLine("Computer name: " + myComputer.Name);

        if (myComputer.Network.IsAvailable)
        {
            Console.WriteLine("Computer is connected to network.");
        }
        else
        {
            Console.WriteLine("Computer is not connected to network.");
        }
    }
}

C# 응용 프로그램에서 MyServices 네임스페이스에 있는 모든 클래스를 호출할 수 있는 것은 아닙니다. 예를 들어 FileSystemProxy 클래스는 호환되지 않습니다. 이 경우에는 VisualBasic.dll에도 포함된 FileSystem에 있는 정적 메서드를 대신 사용할 수 있습니다. 그러한 메서드 중 하나를 사용하여 디렉터리를 복제하는 방법의 예는 다음과 같습니다.

// Duplicate a directory
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(
    @"C:\original_directory",
    @"C:\copy_of_original_directory");

참고 항목

참조

네임스페이스(C# 프로그래밍 가이드)

네임스페이스 사용(C# 프로그래밍 가이드)

개념

C# 프로그래밍 가이드