關(guān)于一些很酷的.Net技巧的翻譯_.Net教程
推薦:淺析ASP.NET中前臺javascript與后臺代碼調(diào)用1.如何在JavaScript訪問C#函數(shù)? 2.如何在JavaScript訪問C#變量? 3.如何在C#中訪問JavaScript的已有變量? 4.如何在C#中訪問JavaScript函數(shù)? 問題1答案如下: javaScript函數(shù)中執(zhí)
一..Net Framework
1. 如何獲得系統(tǒng)文件夾
使用System.Envioment類的GetFolderPath方法;例如:
Environment.GetFolderPath( Environment.SpecialFolder.Personal )
2. 如何獲得正在執(zhí)行的exe文件的路徑
1) 使用Application類的ExecutablePath屬性
2) System.Reflection.Assembly.GetExecutingAssembly().Location
3. 如何檢測操作系統(tǒng)的版本
使用Envioment的OSVersion屬性,例如:
以下為引用的內(nèi)容:
OperatingSystem os = Environment.OSVersion; MessageBox.Show(os.Version.ToString()); MessageBox.Show(os.Platform.ToString()); |
4. 如何根據(jù)完整的文件名獲得文件的文件名部分、
使用System.IO.Path類的方法GetFileName或者GetFileNameWithoutExtension方法
5. 如何通過文件的全名獲得文件的擴展名
使用System.IO.Path.GetExtension靜態(tài)方法
6. Vb和c#的語法有什么不同click here
7. 如何獲得當(dāng)前電腦用戶名,是否聯(lián)網(wǎng),幾個顯示器,所在域,鼠標(biāo)有幾個鍵等信息
使用System.Windows.Forms. SystemInformation類的靜態(tài)屬性
8. 修飾Main方法的[STAThread]特性有什么作用
標(biāo)示當(dāng)前程序使用單線程的方式運行
9. 如何讀取csv文件的內(nèi)容
通過OdbcConnection可以創(chuàng)建一個鏈接到csv文件的鏈接,鏈接字符串的格式是:"Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq=" cvs文件的文件夾路徑 " Extensions=asc,csv,tab,txt; Persist Security Info=False";
創(chuàng)建連接之后就可以使用DataAdapter等存取csv文件了。
詳細(xì)信息見此處
10. 如何獲得磁盤開銷信息,代碼片斷如下,主要是調(diào)用kernel32.dll中的GetDiskFreeSpaceEx外部方法。
以下為引用的內(nèi)容:
public sealed class DriveInfo public static long GetInfo(string drive, out long available, out long total, out long free) public static DriveInfoSystem GetInfo(string drive) public struct DriveInfoSystem public DriveInfoSystem(string drive, long result, long available, long total, long free) |
可以通過
DriveInfoSystem info = DriveInfo.GetInfo("c:");來獲得指定磁盤的開銷情況
11.如何獲得不區(qū)分大小寫的子字符串的索引位置
1)通過將兩個字符串轉(zhuǎn)換成小寫之后使用字符串的IndexOf方法:
以下為引用的內(nèi)容:
string strParent = "The Codeproject site is very informative."; string strChild = "codeproject"; // The line below will return -1 when expected is 4. // The line below will return proper index |
2)
一種更優(yōu)雅的方法是使用System.Globalization命名空間下面的CompareInfo類的IndexOf方法:
以下為引用的內(nèi)容:
using System.Globalization; string strParent = "The Codeproject site is very informative."; string strChild = "codeproject"; int i = Compare.IndexOf(strParent,strChild,CompareOptions.IgnoreCase); |
二. OOPs
1. 什么是復(fù)制構(gòu)造函數(shù)
我們知道構(gòu)造函數(shù)是用來初始化我們要創(chuàng)建實例的特殊的方法。通常我們要將一個實例賦值給另外一個變量c#只是將引用賦值給了新的變量實質(zhì)上是對同一個變量的引用,那么我們怎樣才可以賦值的同時創(chuàng)建一個全新的變量而不只是對實例引用的賦值呢?我們可以使用復(fù)制構(gòu)造函數(shù)。
我們可以為類創(chuàng)造一個只用一個類型為該類型的參數(shù)的構(gòu)造函數(shù),如:
以下為引用的內(nèi)容:
http://m.dounai2.com/ |
使用上面的構(gòu)造函數(shù)我們就可以復(fù)制一份新的實例值,而非賦值同一引用的實例了。
以下為引用的內(nèi)容:
class Student public Student(string name) public string Name class Final { static void Main() { Student student = new Student ("A"); Student NewStudent = new Student (student); student.Name = "B"; System.Console.WriteLine("The new student's name is {0}", NewStudent.Name); } } The new student's name is A. |
分享:解讀VS2008中查看.NET源碼的設(shè)置方法在Visual Studio 2008中可以通過調(diào)試進入。NET Framework的源代碼,從這個意義上說,.NET Framework是開放部分源代碼了,但現(xiàn)在只支持調(diào)試模式下進入源代碼。而其,這個功能在Visual Studi
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實例(可帶附件)
- js實現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實現(xiàn)
- Asp.Net 無刷新文件上傳并顯示進度條的實現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net頁面?zhèn)髦禍y試實例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲過程實現(xiàn)分頁示例代碼
- 相關(guān)鏈接:
- 教程說明:
.Net教程-關(guān)于一些很酷的.Net技巧的翻譯。