Use my namespace in C #

Source: Internet
Author: User

I used to write a small program with VB.net. I feel that my namespace is really good to use. Now I am studying C #, and it is always troublesome to access application settings. Later, I found the method to use my namespace in C # On msdn. As follows (the following content is transferred from msdn ):

Microsoft. visualBasic. the myservices namespace (My in Visual Basic) provides many. net Framework class, allowing you to write code that can interact with computers, applications, settings, resources, and other resources. Although the myservices namespace was originally designed to use Visual Basic, it can also be used in C # applications.

For more information about using the myservices namespace in Visual Basic, see use my development.

Add reference

Before using the myservices class in the solution, you must add a reference to the Visual Basic library.

Add reference to the Visual Basic Library
In Solution Explorer, right-click the reference node and select Add reference ".

After the "Reference" dialog box appears, scroll down the list and select "Microsoft. VisualBasic. dll ".

You may also need to include the following lines in the using section at the beginning of the program.

C #
Copy code
Using Microsoft. VisualBasic. devices;
Example

This example calls various static methods contained in the myservices namespace. To compile this code, you must add a reference to Microsoft. VisualBasic. dll in the project.

C #
Copy code
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 .");
}
}
}
Not all classes in the myservices namespace can be called from the C # application: for example, the filesystemproxy class is incompatible. In this particular case, you can use a static method that is part of filesystem (which is also included in VisualBasic. dll. For example, the following describes how to use this method to copy directories:

C #
Copy code
// Duplicate a directory
Microsoft. VisualBasic. fileio. filesystem. copydirectory (
@ "C:/original_directory ",
@ "C:/copy_of_original_directory ");

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/madalin/archive/2007/03/09/1525314.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.