c# 如何使用 My 命名空間
Microsoft.VisualBasic.MyServices 命名空間(在 Visual Basic 中為 My)使訪問多個 .NET 類變得輕松直觀,讓你能夠編寫與計算機(jī)、應(yīng)用程序、設(shè)置、資源等交互的代碼。 雖然最初設(shè)計用于 Visual Basic,但 MyServices
命名空間仍可用于 C# 應(yīng)用程序。
添加引用
可以在解決方案中使用 MyServices
類之前,必須添加對 Visual Basic 庫的引用。
添加對 Visual Basic 庫的引用
- 在解決方案資源管理器中,右鍵單擊“引用”節(jié)點并選擇“添加引用” 。
- 出現(xiàn)“引用”對話框時,向下滾動列表,然后選擇“Microsoft.VisualBasic.dll”。
同時建議將以下行包括在程序開頭的 using 部分。
using Microsoft.VisualBasic.Devices;
示例
此示例調(diào)用 MyServices 命名空間中包含的各種靜態(tài)方法。 若要編譯此代碼,必須向項目添加對 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."); } } }
并不是 MyServices
命名空間中的所有類均可從 C# 應(yīng)用程序中調(diào)用:例如,F(xiàn)ileSystemProxy 類不兼容。 在此特定情況下,可以改為使用屬于 FileSystem 的靜態(tài)方法,這些方法也包含在 VisualBasic.dll 中。 例如,下面介紹了如何使用此類方法來復(fù)制目錄:
// Duplicate a directory Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory( @"C:\original_directory", @"C:\copy_of_original_directory");
以上就是c# 如何使用 My 命名空間的詳細(xì)內(nèi)容,更多關(guān)于c# 命名空間的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C#多線程同步:Mutex與Semaphore的區(qū)別及使用場景詳解
這篇文章主要介紹了C#多線程同步:Mutex與Semaphore的區(qū)別及使用場景,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-03-03關(guān)于C#泛型列表List<T>的基本用法總結(jié)
本篇文章主要是對C#中泛型列表List<T>的基本用法進(jìn)行了詳細(xì)的總結(jié)介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-01-01C#?基于TCP?實現(xiàn)掃描指定ip端口的方式示例
本文主要介紹了C#基于TCP實現(xiàn)掃描指定ip端口的方式示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11OpenCvSharp實現(xiàn)Mat對象簡單的像素操作
這篇文章主要介紹了OpenCvSharp實現(xiàn)Mat對象簡單的像素操作,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11