一..Net Framework 1 使用System.Envioment Environment.GetFolderPath( Environment.SpecialFolder.Personal ) 2 1 2 3 使用Envioment OperatingSystem os = Environment.OSVersion; MessageBox.Show(os.Version.ToString()); MessageBox.Show(os.Platform.ToString()); 4 使用System.IO.Path 5 使用System.IO.Path.GetExtension 6 7 使用System.Windows.Forms. SystemInformation 8 标示当前程序使用单线程的方式运行 9 通过OdbcConnection 创建连接之后就可以使用DataAdapter 详细信息见此处 10. 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 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) 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. 我们知道构造函数是用来初始化我们要创建实例的特殊的方法。通常我们要将一个实例赋值给另外一个变量c# 我们可以为类创造 public Student(Student student) { this.name = student.name; } 使用上面的构造函数我们就可以复制一份新的实例值,而非赋值同一引用的实例了。 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); } } 2 就是静态的只读变量,它通常在静态构造函数中赋值。 class Numbers { public readonly int m; public static readonly int n; public Numbers(int x) { m = x; } static Numbers() { n = 100; } } //其中n就是一个只读的常量,对于该类的所有实例他只有一种值,而m则根据实例不同而不同 三.VS.Net IDE 1. 2 3 通过工具 四.WinForm 1 通过设置form form1.Text = string. Empty; form1.ControlBox = false; 2 见原作 3 设置form 4 1 <a href=”mailto:email@address1.com,email@address2.com?cc=email@address3.com&Subject=Hello&body=Happy New Year”>some text</a> 2) Process process = new Process(); process.StartInfo.FileName = "mailto:email@address1.com,email@address2.com?subject=Hello&cc=email@address3.com&bcc=email@address4.com&body=Happy New Year" ; process.Start(); 5 需要获得通过Screen.GetWorkingArea(this).Width 五.Button 1 可以设置form 2. 可以设置form 3. Button1.PerformClick 六.Combo Box 1 comboBox1.Items.AddRange (FontFamily.Families); 七.TextBox 1 textBox1.ContextMenu = new ContextMenu(); 2,3 4 textBox1.SelectionStart = textBox1.Text.Length; |