zoukankan      html  css  js  c++  java
  • 在C#中使用My命名空间

    以前用VB.net写过一个小程序,感觉这个My命名空间用起来确实很爽。现在学习C#,在访问应用程序设置的时候总觉得麻烦。后来在MSDN找到了在C#中使用My命名空间的方法。如下(以下内容转自MSDN):

    Microsoft.VisualBasic.MyServices 命名空间(Visual Basic 中的 My)提供对许多 .NET Framework 类的简单直观的访问,使您能够编写可与计算机、应用程序、设置、资源等交互的代码。虽然 MyServices 命名空间最初是为使用 Visual Basic 而设计的,但它也可以在 C# 应用程序中使用。

    有关在 Visual Basic 中使用 MyServices 命名空间的更多信息,请参见使用 My 开发。

    添加引用

    在解决方案中使用 MyServices 类之前,必须添加一个对 Visual Basic 库的引用。

    添加对 Visual Basic 库的引用
    在“解决方案资源管理器”中右击“引用”节点,再选择“添加引用”。

    出现“引用”对话框后,向下滚动列表,选择“Microsoft.VisualBasic.dll”。

    您可能还需要在程序开头的 using 节中包括以下行。

    C#

    using Microsoft.VisualBasic.Devices;
    示例

    此示例调用 MyServices 命名空间中包含的各种静态方法。要编译此代码,必须在项目中添加一个对 Microsoft.VisualBasic.DLL 的引用。

    C#


     1 using System;
     2 using Microsoft.VisualBasic.Devices;
     3 
     4 class TestMyServices
     5 {
     6     static void Main()
     7     {
     8         // Play a sound with the Audio class:
     9         Audio myAudio = new Audio();
    10         Console.WriteLine("Playing sound");
    11         myAudio.Play(@"c:\WINDOWS\Media\chimes.wav");
    12 
    13         // Display time information with the Clock class:
    14         Clock myClock = new Clock();
    15         Console.Write("Current day of the week: ");
    16         Console.WriteLine(myClock.LocalTime.DayOfWeek);
    17         Console.Write("Current date and time: ");
    18         Console.WriteLine(myClock.LocalTime);
    19         
    20         // Display machine information with the Computer class:
    21         Computer myComputer = new Computer();
    22         Console.WriteLine("Computer name: " + myComputer.Name);
    23 
    24         if (myComputer.Network.IsAvailable)
    25         {
    26             Console.WriteLine("Computer is connected to network.");
    27         }
    28         else
    29         {
    30             Console.WriteLine("Computer is not connected to network.");
    31         }
    32     }
    33 

    并不是 MyServices 命名空间中的所有的类都可以从 C# 应用程序调用:例如 FileSystemProxy 类就不兼容。在这种特定情况下,可以改用作为 FileSystem(它也包含在 VisualBasic.dll中)的一部分的静态方法。例如,下面介绍了如何使用这样的方法来复制目录:

    C#

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

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/madalin/archive/2007/03/09/1525314.aspx

  • 相关阅读:
    qemuimg convert 转换vmdk 等虚拟机文件到dd
    golang 占位符%d %t %v
    QT插件vs报错。 The system cannot find the path specified. 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(170,5): error MSB6006: “cmd.exe”已退出,代码为 3
    兆芯,ZXC4580
    jenkins 构建任务 —— 微服务依赖其它微服务
    jenkins构建项目后主动杀死进程再重启进程。
    升级jenkins到最新版本,并安装git插件
    golang基础 自定义类型和类型别名(type)
    SpinalWorkshop实验笔记(三)
    SpinalWorkshop实验笔记(一)
  • 原文地址:https://www.cnblogs.com/jasonoiu/p/1507360.html
Copyright © 2011-2022 走看看