欧美日韩精品在线,国内精品久久久久久久久,一级毛片恃级毛片直播,清纯唯美亚洲综合欧美色

關(guān)于一些很酷的.Net技巧的翻譯_.Net教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:淺析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
{
[DllImport("kernel32.dll", EntryPoint = "GetDiskFreeSpaceExA")]
private static extern long GetDiskFreeSpaceEx(string lpDirectoryName,
out long lpFreeBytesAvailableToCaller,
out long lpTotalNumberOfBytes,
out long lpTotalNumberOfFreeBytes);

public static long GetInfo(string drive, out long available, out long total, out long free)
{
return GetDiskFreeSpaceEx(drive, out available, out total, out free);
}

public static DriveInfoSystem GetInfo(string drive)
{
long result, available, total, free;
result = GetDiskFreeSpaceEx(drive, out available, out total, out free);
return new DriveInfoSystem(drive, result, available, total, free);
}
}

public struct DriveInfoSystem
{
public readonly string Drive;
public readonly long Result;
public readonly long Available;
public readonly long Total;
public readonly long Free;

public DriveInfoSystem(string drive, long result, long available, long total, long free)
{
this.Drive = drive;
this.Result = result;
this.Available = available;
this.Total = total;
this.Free = 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.
int i = strParent.IndexOf(strChild);

// The line below will return proper index
int j = strParent.ToLower().IndexOf(strChild.ToLower());

2)

一種更優(yōu)雅的方法是使用System.Globalization命名空間下面的CompareInfo類的IndexOf方法:

以下為引用的內(nèi)容:

using System.Globalization;

string strParent = "The Codeproject site is very informative.";

string strChild = "codeproject";
// We create a object of CompareInfo class for a neutral culture or a culture insensitive object
CompareInfo Compare = CultureInfo.InvariantCulture.CompareInfo;

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/
public Student(Student student)
{
this.name = student.name;
}

使用上面的構(gòu)造函數(shù)我們就可以復(fù)制一份新的實例值,而非賦值同一引用的實例了。

以下為引用的內(nèi)容:

class Student
{
private string name;

public Student(string name)
{
this.name = name;
}
public Student(Student student)
{
this.name = student.name;
}

public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}

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

共2頁上一頁12下一頁
來源:模板無憂//所屬分類:.Net教程/更新時間:2009-09-07
相關(guān).Net教程