.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. 如何檢測(cè)操作系統(tǒng)的版本
使用envioment的osversion屬性,例如:
operatingsystem os = environment.osversion;
messagebox.show(os.version.tostring());
messagebox.show(os.platform.tostring());
4. 如何根據(jù)完整的文件名獲得文件的文件名部分
使用system.io.path類的方法getfilename或者getfilenamewithoutextension方法
5. 如何通過(guò)文件的全名獲得文件的擴(kuò)展名
使用system.io.path.getextension靜態(tài)方法
6. vb和c#的語(yǔ)法有什么不同click here
7. 如何獲得當(dāng)前電腦用戶名,是否聯(lián)網(wǎng),幾個(gè)顯示器,所在域,鼠標(biāo)有幾個(gè)鍵等信息
使用system.windows.forms. systeminformation類的靜態(tài)屬性
8. 修飾main方法的[stathread]特性有什么作用
標(biāo)示當(dāng)前程序使用單線程的方式運(yùn)行
9. 如何讀取csv文件的內(nèi)容
通過(guò)odbcconnection可以創(chuàng)建一個(gè)鏈接到csv文件的鏈接,鏈接字符串的格式是:"driver={microsoft text driver (*.txt;*.csv)};dbq="+cvs文件的文件夾路徑+" extensions=asc,csv,tab,txt; persist security info=false";
創(chuàng)建連接之后就可以使用dataadapter等存取csv文件了。
詳細(xì)信息見(jiàn)此處
10. 如何獲得磁盤(pán)開(kāi)銷信息,代碼片斷如下,主要是調(diào)用kernel32.dll中的getdiskfreespaceex外部方法。
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;
}
}
可以通過(guò)driveinfosystem info = driveinfo.getinfo("c:");來(lái)獲得指定磁盤(pán)的開(kāi)銷情況
11.如何獲得不區(qū)分大小寫(xiě)的子字符串的索引位置
1)通過(guò)將兩個(gè)字符串轉(zhuǎn)換成小寫(xiě)之后使用字符串的indexof方法:
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方法:
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);
國(guó)內(nèi)最大的酷站演示中心!新聞熱點(diǎn)
疑難解答
圖片精選