C#代碼也VB

來源:互聯網
上載者:User

習慣於用某一種語言做開發,時間長了以後很多人可能會對其它語言有排斥或抵觸,其實... 退一步海闊天空!

比如:經常看到有人問"如何用c# ping 網址?",園子裡搜尋了一下:[c#下實現ping操作]這篇算是總結得比較全面了,但其實...如果願意暫時從C#的世界中退出來環顧一下周圍,方法更簡單:

先添加對Microsoft.VisualBasic的引用,然後參考下面的代碼:

...using Microsoft.VisualBasic.Devices;...Computer myComputer = new Computer();Boolean ping = myComputer.Network.Ping("www.cnblogs.com");if (ping){Response.Write("您的機器可以上部落格園!");}else{Response.Write("部落格園網站無法訪問!");}

再比如:如何用c#做漢字的簡<-->繁轉換?

using Microsoft.VisualBasic;...Response.Write(Strings.StrConv("菩提樹下的楊過", VbStrConv.TraditionalChinese, 0));

這樣就將簡體中文換為繁體了,類似的:

Response.Write(Strings.StrConv("菩提樹下的楊過", VbStrConv.SimplifiedChinese, 0));

這樣就可以將繁體中文轉換為簡體

 

如何得到當前webApplication的程式集名稱以運行時目錄?

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/>程式集名稱:" + app.Info.AssemblyName);            Response.Write("<br/>程式集運行時所在目錄:" + app.Info.DirectoryPath);        }           }}

 

如何搜尋某目錄及其子目錄中檔案內容包含'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/>");            }                    }           }}

 

上面的代碼將搜尋c:\temp以所有子目錄中包含"abc"的檔案(不區分大小寫)

 

文中列出的幾個小應用只能算是拋磚引玉,如果大家發現VB.Net中更好玩、更簡潔的應用,歡迎回貼.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.