国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

編程技巧:.Net Framework

2024-07-21 02:30:09
字體:
來源:轉載
供稿:網友

.net framework

1. 如何獲得系統文件夾

使用system.envioment類的getfolderpath方法;例如:

environment.getfolderpath( environment.specialfolder.personal )

2. 如何獲得正在執行的exe文件的路徑

1) 使用application類的executablepath屬性

2) system.reflection.assembly.getexecutingassembly().location

3. 如何檢測操作系統的版本

使用envioment的osversion屬性,例如:

operatingsystem os = environment.osversion;

messagebox.show(os.version.tostring());

messagebox.show(os.platform.tostring());

4. 如何根據完整的文件名獲得文件的文件名部分

使用system.io.path類的方法getfilename或者getfilenamewithoutextension方法

5. 如何通過文件的全名獲得文件的擴展名

使用system.io.path.getextension靜態方法

6. vb和c#的語法有什么不同click here

7. 如何獲得當前電腦用戶名,是否聯網,幾個顯示器,所在域,鼠標有幾個鍵等信息

使用system.windows.forms. systeminformation類的靜態屬性

8. 修飾main方法的[stathread]特性有什么作用

標示當前程序使用單線程的方式運行

9. 如何讀取csv文件的內容

通過odbcconnection可以創建一個鏈接到csv文件的鏈接,鏈接字符串的格式是:"driver={microsoft text driver (*.txt;*.csv)};dbq="+cvs文件的文件夾路徑+" extensions=asc,csv,tab,txt; persist security info=false";

創建連接之后就可以使用dataadapter等存取csv文件了。

詳細信息見此處

10. 如何獲得磁盤開銷信息,代碼片斷如下,主要是調用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;
}
}

可以通過driveinfosystem info = driveinfo.getinfo("c:");來獲得指定磁盤的開銷情況

11.如何獲得不區分大小寫的子字符串的索引位置

1)通過將兩個字符串轉換成小寫之后使用字符串的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) 一種更優雅的方法是使用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);

國內最大的酷站演示中心!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丰台区| 湛江市| 泰来县| 长寿区| 和顺县| 广水市| 香港| 萨嘎县| 怀柔区| 灯塔市| 商水县| 屏山县| 黔西| 耿马| 靖州| 大渡口区| 孝感市| 新泰市| 漳平市| 青河县| 沙洋县| 平利县| 安远县| 定边县| 施甸县| 乡宁县| 大冶市| 开封县| 郴州市| 荔波县| 沙雅县| 左贡县| 和政县| 江达县| 武夷山市| 隆昌县| 克东县| 天台县| 玛多县| 报价| 喀喇沁旗|