本示例演示了委托类型。它演示了如何将委托映射到静态方法和实例方法,以及如何组合它们以创建多路广播委托// bookstore.csusing System;// 用于处理书店的一组类:namespace Bookstore { using System.Collections; // 描述图书列表中的一本书: public s……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3265浏览 2324个赞
本示例演示了条件方法,它们提供一种功能强大的机制,通过它可以根据是否定义了符号来包括或省略方法调用。// CondMethod.cs// 编译时使用:/target:library /d:DEBUGusing System; using System.Diagnostics;namespace TraceFunctions { publ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3081浏览 599个赞
本示例演示如何访问命令行,并演示访问命令行参数数组的两种方法。// cmdline1.cs// 参数:A B Cusing System;public class CommandLine{ public static void Main(string[] args) { // Length 属性用于获取数组的长度。 ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2314浏览 1282个赞
本示例演示了 C# 程序如何能够与非托管 COM 组件交互操作// interop1.cs// 用“csc /R:QuartzTypeLib.dll interop1.cs”生成using System;class MainClass { /**************************************************……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1965浏览 2733个赞
本示例演示如何实现可与 foreach 语句一起使用的集合类// tokens2.csusing System;using System.Collections;public class Tokens: IEnumerable{ private string[] elements; Tokens(string source, cha……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2720浏览 2567个赞
本示例演示如何实现可与 foreach 语句一起使用的集合类// tokens.csusing System;// 使命名空间 System.Collections 可用:using System.Collections;// 声明 Tokens 类:public class Tokens : IEnumerable{ private……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2586浏览 675个赞
本示例演示了如何创建自定义属性类,如何在代码中使用这些类,以及如何通过反射查询它们// AttributesTutorial.cs// 本示例表明类属性和方法属性的用法。using System;using System.Reflection;using System.Collections;// IsTested 类是用户定义的自定义属性类……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2262浏览 792个赞
本示例介绍并演示 C# 中的数组是如何工作的// 版权所有 (C) Microsoft Corporation。保留所有权利。// arrays.csusing System;class DeclareArraysSample{ public static void Main() { // 一维数组 ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1872浏览 1026个赞
本示例演示了如何使用匿名委托来计算员工的薪水奖金。使用匿名委托简化了程序,因为无需再定义一个单独的方法。(-:The data for each employee is stored in an object containing personal details as well as a delegate that references the algor……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2742浏览 1903个赞
C#用匿名方法定义委托//用匿名方法定义委托 class Program { delegate string MyDelagate(string val); static void Main(string[] args) { string str1 = " 匿名方法外部 &……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1579浏览 2290个赞
一个将汉字转换成拼音的C#类代码using System;using System.Collections.Generic;using System.Text;namespace Common{ public class Pinyin { private static int[] pyvalue=new int[]……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2356浏览 543个赞
C#返回字符串的字节长度,一个中文算两个字符 //得到字符串的长度 public static int GetLength(string str) { if (str.Length == 0) return 0; ASCIIEncoding ascii = new ASCI……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2873浏览 1055个赞
C#抓取网页代码存在字符串里public static string GetWebPageAsString(string url) { HttpWebRequest httpWebRequest =(HttpWebRequest)WebRequest.Create(url); // you may need these next two……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2561浏览 2777个赞
C# 下载网页并在控制台输出using System;using System.Net;using System.Text;using System.IO;namespace Test {class GetWebPage { public static void Main(string[] args) { for(int i……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1493浏览 1626个赞
C# 使用属性范例代码public class Plane { protected double mySpeed = 300.0D; public double TopSpeed { get {return mySpeed;} ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1979浏览 2457个赞
C# 运算符重载使用范例public class Plane { public virtual double TopSpeed() { return 300.0D;} public static bool operator>(Plane one, Plane two) { return one.To……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1316浏览 2255个赞
C# 虚函数使用范例using System;namespace Test2 { class Plane { public double TopSpeed() { return 300.0D; } } class Jet : Plane { public double TopSp……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2867浏览 1650个赞
C#构造函数、静态构造函数、析构函数的用法using System;class Test2 { static int i; static Test2() { // a constructor for the entire class called //once before……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3119浏览 242个赞
C#格式化输出内容nt k = 16;Console.WriteLine(" '{0,-8}'",k); // produces: '16 'Console.WriteLine(" '{0,8}'",k); // pro……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2004浏览 454个赞
C# xml文件反序列化读入数据到objectpublic static object DeSerializeFromXmlString(System.Type typeToDeserialize, string xmlString) { byte[] bytes = System.Text.Encoding.UTF8.GetBytes(xml……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2940浏览 1054个赞
C#简单的写入xml文件的方法StringWriter stringWriter = new StringWriter();XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);xmlTextWriter.Formatting = Formatting.Indented;xml……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2906浏览 970个赞
C#写入对象或者集合类型数据到xml文件public static string SerializeToXmlString(object objectToSerialize) { MemoryStream memoryStream = new MemoryStream(); System.Xml.Serialization.XmlSer……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3214浏览 2411个赞
C# 原始的方法写入xml文件static void writeTree(XmlNode xmlElement, int level) { String levelDepth = ""; for(int i=0;i<level;i++) { levelDepth += " &quo……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1929浏览 531个赞
C#通过流写入一行数据到文件using System;using System.IO;public class WriteFileStuff {public static void Main() { FileStream fs = new FileStream("c:\\tmp\\WriteFileStuff.txt&qu……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2284浏览 1006个赞
C#一次性写入全部文件到文件using System;namespace PlayingAround { class ReadAll { public static void Main(string[] args) { string myText = "Line1" + Enviro……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2644浏览 663个赞
C#逐行读取文件,对于大文件的读取非常有用StreamReader sr = new StreamReader("fileName.txt");string line;while((line= sr.ReadLine()) != null) { Console.WriteLine("xml template:&quo……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1626浏览 2048个赞
C#读取文件的所有行到数组using System;namespace PlayingAround { class ReadAll { public static void Main(string[] args) { string[] lines = System.IO.File.ReadAllLine……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1355浏览 2934个赞
C#通过文件流读取文件内容public static string getFileAsString(string fileName) { StreamReader sReader = null; string contents = null; try { FileStream fileStream = new FileSt……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3215浏览 2922个赞
C#把整个文件的内容读入字符串变量using System;namespace PlayingAround { class ReadAll { public static void Main(string[] args) { string contents = System.IO.File.ReadAl……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3183浏览 574个赞
c#通过DES加密算法加密大文件using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.U……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1461浏览 2242个赞
一个C#控制台程序演示hello worldusing System;public class HelloWorld{ public static void Main(string[] args) { Console.Write("Hello World!"); }}……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1783浏览 2568个赞
C# LINQ判断素数的简单代码static bool IsPrime(int n){ return Enumerable.Range(2, (int) Math.Sqrt(n)-1).All(i => n%i != 0);}……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2217浏览 235个赞
C# 符合RFC3986标准的urlencode 类 /// <summary> /// Provides implementation of RFC3986 Percent Encoding mechanism. /// </summary> public class RFC3986Encoder ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1899浏览 2796个赞
C#用钩子获得按键信息实例 窗体相关代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;us……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1357浏览 1949个赞
C#访问SqlServer设置链接超时,这段代码设置超时时间为60秒,默认为30秒using (connection) { SqlCommand sqlcommand = connection.CreateCommand(); sqlcommand.CommandTimeout = 60; //default is 30 seconds……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2528浏览 699个赞
C#查询SqlServer数据库并返回单个值static public string GetSqlAsString(string sqlText, SqlParameter[] sqlParameters, string databaseConnectionSt……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2126浏览 243个赞
之前我贴过一段很简单的C#生成plist文件的代码,但是反过来如果要读取plist文件呢?有没有实现这样功能的类库呢?答案是肯定的,下午在网上找了一个iphone-plist-net库试用了一下感觉很是方便。来源:http://blog.csdn.net/wangqiuyun/article/details/7931972 //写……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1347浏览 2409个赞
C#从XmlDocument返回一个指定的属性string total = xmlDocument.SelectSingleNode("Surveys/Survey[@name='Beer']/cellName[@name='MatureBlueCollarMen']").Attributes……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3036浏览 1850个赞
C#输出xmlNodeList到控制台 public static string ToHTML(XmlNodeList xmlNodeList) { StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlTextWriter = new Xm……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2319浏览 1157个赞
C# 执行外部命令///<summary> ///executes a system command from inside csharp ///</summary> ///<param name="cmd">a dos type command like "isql ...&qu……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3290浏览 347个赞
C#从 web service检索xml文档并应用 XSLT public class ScreenerQuestionsToAsk : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { GetSurv……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2235浏览 2370个赞
C# FTP操作类using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;namespace Utility{ public class FtpUpDown { strin……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3185浏览 153个赞
C#实现文件下载,支持断点续传using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.IO;using System.Text;using System.Net;na……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2274浏览 2654个赞
C#字符串转换成字节数组using System.Text;public static byte[] ConvertStringToByteArray(string stringToConvert){ return (new UnicodeEncoding()).GetBytes(stringToConvert);}……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2986浏览 1203个赞
C#转换集合类型为html代码输出public static string ToHTML(Hashtable hashtable) { string tmp = ""; IDictionaryEnumerator myEnumerator = hashtable.GetEnumerator(); whi……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2657浏览 2274个赞