C#修改电脑密码,重置windows密码DirectoryEntry实现转自:http://blog.csdn.net/sufei1013/article/details/8073184 C#修改电脑密码方法如下 /// <summary> /// 更……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2353浏览 994个赞
C#使用委托实现的快速排序算法class QuickSort { private delegate int CmpOp(object Left, object Right); private void swap(object[] Array, int Left, int Right, CmpOp Cmp) { ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2808浏览 1509个赞
C#快速排序算法代码演示class Quicksort { private void swap(int[] Array, int Left, int Right) { int temp = Array[Right]; Array[Right] = Array[Left]; ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2957浏览 2438个赞
C# Aggregate and Sum 使用范例using System;using System.Linq;using System.Collections;using System.Collections.Generic;public class MainClass { public static void Main() { ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1593浏览 883个赞
C#在数组上使用Aggregateusing System;using System.Collections;using System.Collections.Generic;using System.Text;using System.Linq;public class MainClass { public static void ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1850浏览 2288个赞
C# Aggregate 用法范例using System;using System.Linq;using System.Collections;using System.Collections.Generic;public class MainClass { public static void Main() { in……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2684浏览 2875个赞
此程序包含一个简单的 LINQ to XML 示例查询。它演示了编写 LINQ to XML 查询所需的最少代码。using System;using System.Collections.Generic;using System.IO;using System.Xml;using System.Linq;using System.Xml.L……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2305浏览 2685个赞
示例演示如何创建一个列表类来实现 IEnumerable 和 yield 关键字,以对列表的内容启用 foreach 迭代using System;using System.Collections.Generic;using System.Text;namespace Yield{ class Yield { p……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1333浏览 870个赞
本示例演示如何使用 XML 将代码编入文档// XMLsample.cs// 编译时使用:/doc:XMLsample.xmlusing System;/// <summary>/// 此处显示类级别摘要文档。 </summary>/// <remarks>/// 较长的注释可通过 remarks 标记与……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2587浏览 1250个赞
本示例演示了如何在 C# 中使用 override 和 new 关键字进行版本控制。版本控制有助于在基类和派生类的演变过程中维护它们之间的兼容性。// versioning.cs// 需要 CS0114public class MyBase { public virtual string Meth1() { return……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2471浏览 1947个赞
C#通过指针读取文件// readfile.cs// 编译时使用:/unsafe// 参数:readfile.txt// 使用该程序读并显示文本文件。using System;using System.Runtime.InteropServices;using System.Text;class FileReader{ const u……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2229浏览 1307个赞
本示例演示如何定义与类或结构之间的转换,以及如何使用此类转换// conversion.csusing System;struct RomanNumeral{ public RomanNumeral(int value) { this.value = value; } // 声明从 int 到 ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1989浏览 842个赞
本示例演示了如何在 C# 中使用非托管代码(使用指针的代码)。// printversion.cs// 编译时使用:/unsafeusing System;using System.Reflection;using System.Runtime.InteropServices;// 为此程序集指定一个版本号:[assembly:Assemb……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1668浏览 2593个赞
C# 通过指针实现的fastcopy,快速拷贝函数// fastcopy.cs// 编译时使用:/unsafeusing System;class Test{ // unsafe 关键字允许在下列 // 方法中使用指针: static unsafe void Copy(byte[] src, int srcIndex,……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2431浏览 2498个赞
本示例演示了下面的线程处理技术。创建、启动和终止线程使用线程池线程同步和互交 ThreadPool.csusing System;using System.Threading;// Fibonacci 类为使用辅助// 线程执行长时间的 Fibonacci(N) 计算提供了一……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1678浏览 2102个赞
本示例演示结构的语法和用法。它还介绍了类与结构之间的重大差异 // struct1.csusing System;struct SimpleStruct{ private int xval; public int X { ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1452浏览 1081个赞
本示例演示了如何通过权限类和权限属性来修改安全权限 // ImperativeSecurity.csusing System;using System.Security;using System.Security.Permissions;using Syst……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2679浏览 2230个赞
C#类和属性的使用 abstractshape.cs// abstractshape.cs// 编译时使用:/target:library// csc /target:library abstractshape.csusing System;public abstract ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1388浏览 2309个赞
本示例演示属性为何是 C# 编程语言必不可少的一个组成部分。它演示了如何声明和使用属性// person.csusing System;class Person{ private string myName ="N/A"; private int myAge = 0; // 声明 string 类型的 ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1854浏览 230个赞
本示例演示了如何使用允许在两个或更多 C# 文件中定义类或结构的分部类型。这就允许多个程序员并行处理一个类的不同部分,并将复杂类的不同方面保存在不同的文件中。 CharTypesPrivate.csusing System;using System.Collections.Gen……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2621浏览 2553个赞
本示例演示了用户定义的类如何能够重载运算符// complex.csusing System;public struct Complex { public int real; public int imaginary; public Complex(int real, int imaginary) { thi……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2054浏览 2150个赞
本示例演示了如何在 C# 中使用 Microsoft Access 数据库。它演示了如何创建数据集并从数据库向该数据集添加表。// OleDbSample.cs// 若要从命令行生成此示例,请使用命令:// csc oledbsample.csusing System;using System.Data;using System.Data.O……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1476浏览 471个赞
C#统计字符串中数字的个数// DigitCounter.cs// 编译时使用:/target:libraryusing System; // 声明与 Factorial.cs 中的命名空间相同的命名空间。这样仅允许将 // 类型添加到同一个命名空间中。namespace Functions { public class Digit……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1732浏览 1449个赞
本示例演示 本示例演示 C# 类如何声明索引器以提供对类的类似数组的访问。。// indexer.cs// 参数:indexer.txtusing System;using System.IO;// 将大文件当作字节数组// 访问的类。public class FileByteArray{ Stream stream; ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2340浏览 2969个赞
C#中dynamic的正确用法 dynamic是FrameWork4.0的新特性。dynamic的出现让C#具有了弱语言类型的特性。编译器在编译的时候不再对类型进行检查,编译期默认dynamic对象支持你想要的任何特性。比如,即使你对GetDynamicObject方法返回的对象一无所……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2247浏览 1339个赞
C#判断操作系统版本//获取系统信息System.OperatingSystem osInfo = System.Environment.OSVersion; //获取操作系统IDSystem.PlatformID platformID = osInfo.Platform;//获取主版本号int versionMajor = osInfo.V……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1707浏览 2948个赞
C#三层架构之数据库访问层代码using System;using System.Data;using System.Data.SqlClient;using System.Configuration;namespace DbBase{ public abstract class Base { #region "Fields……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2283浏览 1816个赞
设计模式C#描述——工厂方法模式演示代码 设计模式C#描述——工厂方法模式工厂方法模式是类的创建模式,又叫做虚拟构造子模式或多态性工厂模式。它的用意是定义一个创建产品对象的工厂接口,将实际创建工作推迟到子类中。简单工厂模式的缺点:由于工厂类集中了所有产品创建逻辑的,如果不能正常工作的话……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1357浏览 1003个赞
很多人喜欢用GUID作为数据表的主键,如果使用无序的GUID,当数据量很大的时候,插入性能会急剧下降,如果非要使用GUID,则可以实用有序的GUID,这样性能的影响会比较小。public static Guid GenerateGuid(){ byte[] guidArray = Guid.NewGuid().ToByteArray(); ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1588浏览 1507个赞
C# 输出MD5和SHA1编码using System;namespace myMethod{ class computeMD5andSHA1 { /// <summary> /// 计算文件的 MD5 值 /// </summary> /// ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1452浏览 326个赞
C#导出数据到Excel或者Word中的代码片段private void Page_Load(object sender, System.EventArgs e) { SqlConnection con=new SqlConnection("server=.;database=pubs;uid=sa;p……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2357浏览 2658个赞
C#实现简单的udp收发的代码 发送 try { Socket s = new Socket(AddressFamily.InterNetwork, Sock……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3152浏览 444个赞
C# DBHelper 第二版, 持续更新 直到完美。 欢迎大家提出意见。作者:ChaoVer /******************************** * Produce: DbHelper * Version: beta 2 * Date: 2012.10.11 ********************************/……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2913浏览 2464个赞
C#安全删除文件目录的代码1. 创建文件夹 (简单,没多考虑) 2. 删除所建文件夹:为防止删除过程中有其他进程引用该文件夹中文件,增加了对此意外情况的考虑。 在本例中,若删除过程中被其他进程引用,等待并循环5次尝试再次删除操作。长时间无法被删除,则删除文件目录失败using System;using System.IO;namespace Ret……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2990浏览 1757个赞
c# 获取 httponly cookie/// <summary>/// WinInet.dll wrapper/// </summary>internal static class CookieReader{ /// <summary> /// Enables the retrieval ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2250浏览 1490个赞
MySQLDriverCS下载地址:……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2331浏览 1143个赞
C#写入日志到文本文件的代码using System.IO;public static void ErrorLog(string mssg) { string FilePath = HttpContext.Current.Server.MapPath("~/log/ErrorLog.txt"); try { if (Fi……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1499浏览 1534个赞
C#委托delegate使用范例using System;using System.Collections.Generic;using System.Text;namespace Delegate { //委托简单说就是可以让方法作为变量进行传递. //定义委托,它定义了可以代表的方法的类型 public delegate void……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1981浏览 125个赞
C#逐行读取文本文件到字符串列表的代码List<string> lines = new List<string>(); using (StreamReader r = new StreamReader("databasefile.txt")) { ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3020浏览 2099个赞
C# 杀掉指定名字的进程程序代码public static void stopNamedProcess(string name) { foreach (Process p in System.Diagnostics.Process.GetProcessesByName(name)) { ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1506浏览 1194个赞
C#写入日志到系统事件日志using System.Diagnostics; EventLog.WriteEntry("Error Title", exp.Message, System.Diagnostics.EventLogEntryType.Error);……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2686浏览 2512个赞
C#从windows剪贴板粘贴内容using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Data;using System.Windows.Forms;public class MainClass……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1424浏览 2422个赞
C# windows form拷贝内容到剪贴板 using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Data; using System.Windows.Forms; ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2137浏览 2059个赞
C#删除文件和文件夹到回收站的代码using System;using Microsoft.VisualBasic.FileIO;namespace leaver{ class Program { static void Main(string[] args) { Conso……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3046浏览 1757个赞
C#使用semaphore 管理异步下载请求 var semaphor = new Semaphore(50, 50); // We allow at most 50 threads for crawling var resultPins = new List<Pin>(); // Results stored ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1885浏览 2593个赞