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

