编程技巧:.Net Framework
|
源代码网整理以下.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 源代码网整理以下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.如何获得不区分大小写的子字符串的索引位置 源代码网整理以下1)通过将两个字符串转换成小写之后使用字符串的IndexOf方法: 源代码网整理以下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) 一种更优雅的方法是使用System.Globalization命名空间下面的CompareInfo类的IndexOf方法: 源代码网整理以下using System.Globalization; 源代码网整理以下string strParent = "The Codeproject site is very informative."; 源代码网整理以下string strChild = "codeproject"; 源代码网整理以下int i = Compare.IndexOf(strParent,strChild,CompareOptions.IgnoreCase); 源代码网供稿. |
