C# 创建Group Object in Active Directoryusing System.DirectoryServices;using System.Reflection; public class ADGroup{ private String ADGRPOUP = "group"; // ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3135浏览 1321个赞
using System.Data;using System.Data.SqlClient;…// Substitute your connection string below in conxString String conxString = “Data Source=MYSERVER; Integrated Securit……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3239浏览 2297个赞
C#检测网络驱动器的剩余磁盘空间using System;using System.Management; class NetworkSpace{ static void Main(string[] args) { SelectQuery query = new SelectQuery( "select……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2565浏览 1048个赞
C#检测光驱里的光盘是否已经加载using System;using System.Management; class App{ public static void Main() { SelectQuery query = new SelectQuery( "select * from win32_logicaldi……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2836浏览 1122个赞
这段代码演示了C#如何通过修改AssemblyInfo.cs文件实现自动版本号// Modify the AssemblyVersion line in the // "AssemblyInfo.cs" file: // Add a "*" to the section you want to increa……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2483浏览 2319个赞
C# 检测pc光驱里是否插入了光盘,需要添加System.Management.dll 的引用using System;using System.Management; namespace CDROMManagement{ class WMIEvent { static void Main(string[] args) ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3193浏览 2097个赞
本代码创建了一个类的索引器用来访问类,就像访问数组一样using System.Collections.Generic;...class Client{ private Dictionary<int, string> invoices = new Dictionary<int, string>(); ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2202浏览 2620个赞
本代码通过ICollection接口的count属性来输出其元素数量using System;using System.Collections; public class CountArray{ public static void Main() { string[] strings = {"Ajax&quo……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1688浏览 554个赞
这段代码通过BitArray来计算素数using System.Collections;...const int LAST_CANDIDATE = 1000;int primes = 0;BitArray candidates = new BitArray (LAST_CANDIDATE, true); for (int i = 2; i ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1721浏览 857个赞
本范例演示了C#中如何在不打开dos窗口的情况下运行控制台程序,同时捕获程序的输出信息// This snippet needs the "System.Diagnostics"// library // Application path and command line argumentsstring Applicatio……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1759浏览 1915个赞
C#枚举类型用于标志位,可以进行与和或操作enum Mammalia{ Bison = 1, Human = 2, Mammal = 255} public class MammalCheck{ public static void Main( ) { //Mammalia pattern……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2443浏览 1960个赞
本代码演示了C#自带的Array.Sort方法排序using System; public class ReverseArraySort{ public static void Main() { string[] strings = {"beta", "alpha", "……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2520浏览 2149个赞
这段代码演示了C#使用二分法快速搜索数组using System; class ArrayBinarySearch{ public static void Main() { int[] ints = {0, 10, 100, 1000, 1000000 }; Console.WriteLine ("A……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2174浏览 2801个赞
这段代码可以把C#的数组倒置过来,主要用到了Array.Reverse方法using System; public class ReverseArray{ public static void Main() { string[] strings = {"beta", "alpha"……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1626浏览 197个赞
C# 读取控制台输入的信息char character = (char) Console.Read(); // returns an int string stringInput = Console.ReadLine();……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3603浏览 2418个赞
C# 给函数传入匿名委托并控制执行指定的次数public delegate int ConsoleDelegate (int value); public class Test{ void ExecuteDelegate (ConsoleDelegate cd, int iterations) { for (int i=1……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2584浏览 1992个赞
C# 重写ToString()方法输出私有变量的代码片段public class MyClass{ private string customer =""; private int customerID = 0; public string Customer { get { return c……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2045浏览 191个赞
C# 重载加号运算符计算两个对象的和public class ValidFloat{ private float value; private bool valid; public ValidFloat (float value, bool valid) { this.value = value; ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1439浏览 1623个赞
模仿老版本的windows上的夜空屏保代码using System;class set_cursor2{ int lastnum; private int RandomNumber(int min, int max){ Random random = new Random(); lastnum = random.Next(mi……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1633浏览 2816个赞
C# 测试代码执行时间的两个方法DateTime startTime = DateTime.Now;Console.WriteLine ("Started: {0}", startTime); // Execute the task to be timedfor (int i=1; i < 100000; i++){}……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1477浏览 1268个赞
本代码片段演示了C#中如何实现IDispose接口,实现资源释放public class MyClass : IDisposable{ public void Dispose() { // release any resources here // when object is about to be garb……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2220浏览 2870个赞
C#获取 NetBIOS和 DNS计算机名static string GetLocalHostName (){ string netBiosName = System.Environment.MachineName; //return netBiosName; // Following method is deprecated……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2797浏览 574个赞
C#代码验证IP地址,包含格式和是否超过255的限制/// <summary> /// Check IP Address, will accept 0.0.0.0 as a valid IP /// </summary> /// <param name="strIP……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2646浏览 2577个赞
C# 从控制台读取数字try{ int number = Convert.ToInt32 (Console.ReadLine()); Console.WriteLine ("Number: " + number);}catch (FormatException e){ Console.WriteLine (……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1509浏览 1472个赞
下面的c#代码片段显示产生随机数输出到控制台。RandomNumber函数的第一个参数为生成的随机数的最小值。第二个参数是最大值+ 1。using System; class Program{ private Random random = new Random(); private int RandomNumber (int ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2825浏览 150个赞
根据给定的网页url地址返回域名/* ** Method 1 (using the build-in Uri-object)*/public static string ExtractDomainNameFromURL_Method1(string Url){ if (!Url.Contains("://")) ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2892浏览 581个赞
下面的c#代码片段使用不同的格式显示日期和时间。using C = System.Console; ...static void Main() { DateTime dateTime = DateTime.Now; C.WriteLine ("d = {0:d}", dateTime ); // mm/dd/yyy……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1989浏览 2981个赞
下面的c#代码片段演示了各种字符串的方法和属性。using System; class StringMethods{ static void Main() { char[] characterArray; int position; string result, string1; s……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1302浏览 2721个赞
C# 定义一个简单的事件(Event)public class MyClass : IDisposable{ public event EventHandler Disposing; public void Dispose() { // release any resources here if (D……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1849浏览 2532个赞
本范例演示了C#如何对一个给定的字符串进行MD5加密/// <summary>/// Calculates a MD5 hash from the given string and uses the given/// encoding./// </summary>/// <param name="Inpu……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2796浏览 214个赞
C#提供了两种方式定义多行字符串变量string couplet1 = "Half a league, half a league,\n" + "Half a league onward,"; string couplet2 = @"All in the valley……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3016浏览 1211个赞
C# 声明变量并赋值的代码演示class VariableDeclarations{ public static void Main() { // Type Identifier Assignment (maximum value) bool aBool; aBool = true; ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2392浏览 1743个赞
本范例介绍了C#中const的用法和一些常量声明class ConstantDeclarations{ public static void Main() { // Type Identifier Initializer const bool aBool = true; co……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1352浏览 660个赞
本范例演示了C#开发GUI程序时如何避免一个超长处理过程占用全部资源,导致界面不能响应用户事件的方法// You need the Threading library to use the // "Thread.Sleep" function// using System.Threading; // This boolean……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1811浏览 2415个赞
本代码演示了如何创建一个unsafe的指针数组记录struct的地址信息class UnsafePointerArray{ public struct AStruct { public int anInteger; } public static void CreatePointerArray() { ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1549浏览 1928个赞
本范例演示怎样通过c#中的XmlSerializer序列化一个普通对象// This is the test class we want to // serialize:[Serializable()]public class TestClass{ private string someString; public string……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2028浏览 2495个赞
C#创建多维数组代码using System; public class MultidimensionalArray{ public static void Main() { int[] lowerBounds = {1, 2, 4}; int[] lengths = {4, 2, 1}; ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2755浏览 2320个赞
C# 里的MD5 算法代码片段using System; public string CreateMD5Hash (string input){ // Use input string to calculate MD5 hash MD5 md5 = System.Security.Cryptography.MD5.Create();……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3056浏览 486个赞
C# 里的Array.CopyTo复制一个数组的部分到另外一个数组using System; public class CopyToArray{ public static void Main() { object[] objects1 = {"one", "two", "……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3227浏览 1748个赞
Array.Copy可以复制整个数组,也可以对数组进行部分复制using System; public class CopyArray{ public static void Main() { int[] integers = new int[] {5, 10, 15}; double[] doubles……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1903浏览 155个赞
C#华氏温度和摄氏温度的相互专函代码片段public static double CelsiusToFahrenheit (string temperatureCelsius){ double celsius = System.Double.Parse (temperatureCelsius); return (celsius *……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2812浏览 2458个赞
C# 克隆整个数组using System; class CloneArray{ public static void Main() { string[] array1 = {"a", "b", "c"}; string[] array2 = (str……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3134浏览 2303个赞
C#通过Array.Clear部分清除数组,这个方法不但可以清除整个数组,还可以部分清除using System; class ArrayClear{ public static void Main() { int[] integers = { 1, 2, 3, 4, 5 }; DumpArray (&qu……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3151浏览 1173个赞
C# 捕获OverflowException异常的代码short shorty = 32767; // largest positive shortint integer = shorty + 1;try{ checked // force compiler to obj……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2984浏览 2154个赞
C#使用快速排序法给一个字符串数组排序class Quicksort { private void quickSwap(string[] Array, int Left, int Right) { string Temp = Array[Right]; Array[Right] = Array[Left]; Array[Left] =……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3019浏览 951个赞