C # The Code is also VB

Source: Internet
Author: User

I am used to developing in a certain language. After a long time, many people may reject or conflict with other languages. In fact!

For example, you may often see someone asking"How can I ping the website using C?", Search in the garden: [C # ping operation] This is a comprehensive summary, but in fact... if you want to temporarily exit from the world of C # and look around, the method is simpler:

First Add a reference to Microsoft. VisualBasic, and then refer to the followingCode:

 
... Using Microsoft. visualBasic. devices ;... computer mycomputer = new computer (); Boolean Ping = mycomputer. network. ping ("www.cnblogs.com"); If (PING) {response. write ("your machine can go to the blog Park! ");} Else {response. Write (" the blog site cannot be accessed! ");}

For example:How to use C # To Simplify Chinese characters <--> traditional conversion?

 
Using Microsoft. VisualBasic;... response. Write (strings. strconv ("Yang Guo under the bodhi tree", vbstrconv. traditionalchinese, 0 ));

In this way, the simplified Chinese is changed to traditional Chinese, similar:

 
Response. Write (strings. strconv ("", vbstrconv. simplifiedchinese, 0 ));

In this way, you can convert traditional Chinese to simplified Chinese

 

How to obtain the current webapplication'sProgramSet Name to runtime directory?

 
Using system; using Microsoft. visualBasic. applicationservices; namespace aspxwebform {public partial class webform1: system. web. UI. page {protected void page_load (Object sender, eventargs e) {applicationbase APP = new applicationbase (); response. write ("<br/> Assembly name:" + app. info. assemblyname); response. write ("<br/> directory where the Assembly runs:" + app. info. directorypath );}}}

 

How do I search for files in a directory and Its subdirectories that contain 'abc?

Using system; using Microsoft. visualBasic. devices; using Microsoft. visualBasic. fileio; namespace aspxwebform {public partial class webform1: system. web. UI. page {protected void page_load (Object sender, eventargs e) {computer mycomputer = new computer (); var list = mycomputer. filesystem. findinfiles ("C: \ temp \", "ABC", true, searchoption. searchallsubdirectories); foreach (VAR item in list) {response. write (item + "<br/> ");}}}}

 

The above code will search for c: \ Temp files containing "ABC" in all subdirectories (Case Insensitive)

 

The several small applications listed in this article can only be regarded as an example. If you find that VB. NET is more fun and concise, you are welcome to reply.

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.