随笔分类 -  C#

摘要:我们知道数据库里的datediff函数可以判断两个时间的时间差,在做统计时,常常会统计:今天的记录,本周的记录,本月的记录,三个月内的记录,本年度记录等等。用datediff函数时的写法大致如下: case "datetimespan": switch (keyword.ToLower()) { case "all": break; ... 阅读全文
posted @ 2012-12-13 16:59 清山博客 阅读(306) 评论(0) 推荐(0)
摘要:Predicate<T> 委托:表示定义一组条件并确定指定对象是否符合这些条件的方法。下面的代码示例使用带有 Array.Find<T> 方法的Predicate<T> 委托搜索Point 结构的数组。如果 X 和 Y 字段的产品大于 100,000,则该代理所代表的方法ProductGT10 将返回 true。Find<T>方法调用数组的每个元素的代理,从而在第一个满足测试条件的点停止。using System; using System.Drawing; public class Example { public static void Ma 阅读全文
posted @ 2012-12-11 15:47 清山博客 阅读(208) 评论(0) 推荐(0)
摘要:using System; namespace FuncDemo { internal class Program { private static void Main() { //类似委托功能 Func<InputArgs, Result> func = TsetFunction; Console.WriteLine("第一种方式:"); Console.WriteLine(func(new InputArgs("zhangqs008", "12... 阅读全文
posted @ 2012-12-11 15:46 清山博客 阅读(376) 评论(0) 推荐(0)
摘要:<script type="text/javascript"> //功能:将回车键转tab键 jQuery(function () { jQuery('input:text:first').focus(); var $inp = jQuery('input:text'); $inp.bind('keydown', function (e) { var key = e.which; if (key == 13) { e.preventDefault(); var nxtIdx = $inp.index(this) + 阅读全文
posted @ 2012-12-06 16:19 清山博客 阅读(1815) 评论(0) 推荐(0)
摘要:1.调用代码入口:using System; namespace 图_图的遍历 { internal class Program { private static void Main(string[] args) { var a = new AdjacencyList<char>(); Console.WriteLine("1.初始化树结构:"); Console.WriteLine("================================="); ... 阅读全文
posted @ 2012-12-03 13:22 清山博客 阅读(335) 评论(0) 推荐(0)
摘要:程序调用入口:using System; namespace Graphic_AdjacencyList { internal class Program { private static void Main(string[] args) { var adjacencyList = new AdjacencyList<char>(); Console.WriteLine("1.初始化树结构:"); Console.WriteLine("=================... 阅读全文
posted @ 2012-12-02 20:39 清山博客 阅读(428) 评论(0) 推荐(0)
摘要:// 方法 1this.historyRichTextBox.Focus();this.historyRichTextBox.Select(historyRichTextBox.TextLength,0);this.historyRichTextBox.ScrollToCaret();// 方法 2richTextBox1.SelectionStart = richTextBox1.TextLength;richTextBox1.Focus(); 阅读全文
posted @ 2012-11-22 20:12 清山博客 阅读(583) 评论(0) 推荐(0)
摘要:方法一: string frameworkInstallDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(); 方法二: public static string GetFrameworkDirectory() { // This is the location of the .Net Framework Registry Key string framworkReg... 阅读全文
posted @ 2012-10-10 20:24 清山博客 阅读(493) 评论(0) 推荐(0)
摘要:在C#中有HttpWebRequest类,可以很方便用来获取http请求,但是这个类对Post方式没有提供一个很方便的方法来获取数据。网上 有很多人提供了解决方法,但都参差不齐,这里我把我使用的方法总结出来,与大家分享。本文精华:实现了post的 时候即可以有字符串的key-value,还可以带文件。Post数据格式Post提交数 据的时候最重要就是把Key-Value的数据放到http请求流中,而HttpWebRequest没有提供一个属性之类的东西可以让我们自由添加 Key-Value,因此就必须手工构造这个数据。根据RFC 2045协议,一个Http Post的数据格式如下:Conten 阅读全文
posted @ 2012-08-20 19:35 清山博客 阅读(701) 评论(0) 推荐(0)
摘要:using System; using System.Diagnostics; using Microsoft.Win32; namespace SimpleContextMenu { /// <summary> /// 在注册表中注册和注销文件上下文菜单. /// </summary> static class FileShellExtension { /// <summary> /// 注册上下文菜单 /// </summary> /// <param name="fileType">... 阅读全文
posted @ 2012-07-24 20:12 清山博客 阅读(301) 评论(0) 推荐(0)
摘要:private void DeserializeJson() { string content = ""; string input = "{'key1':{'Name':'ZhangSan','Age':20},'key2':{'Name':'LiSi','Age':21},'key3':{'Name':'WangWu','Age':22}}"; try { Ja 阅读全文
posted @ 2012-07-24 20:07 清山博客 阅读(223) 评论(0) 推荐(0)
摘要:/// <summary> /// 开机启动项 /// </summary> /// <param name=\"Started\">是否启动</param> /// <param name=\"name\">启动值的名称</param> /// <param name=\"path\">启动程序的路径</param> public static void RunWhenStart(bool Started, string name, st 阅读全文
posted @ 2012-07-24 12:55 清山博客 阅读(222) 评论(0) 推荐(0)
摘要:用于批量处理数码相机拍摄相片太大,便于网络上传。资源下载:http://sdrv.ms/KV76iW 阅读全文
posted @ 2012-06-24 16:14 清山博客 阅读(189) 评论(0) 推荐(0)
摘要:利用闲暇时间,写了个简单的代码查看工具,也仅仅是方便在不打开vs的情况下阅读代码。不多说,直接贴图,传代码。源代码下载:http://sdrv.ms/KV76iW 阅读全文
posted @ 2012-06-09 16:42 清山博客 阅读(199) 评论(0) 推荐(0)
摘要:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Collections; namespace Framework { /// <summary> /// 将xml转换为json /// </summary> public class XmlToJson { /// <summary> /// 将xml转换为json ///... 阅读全文
posted @ 2012-06-05 20:20 清山博客 阅读(349) 评论(0) 推荐(0)
摘要:using System; using System.Collections.Generic; using System.Text; using System.Reflection; namespace ObjectCompare { public class Person { public string Name { get; set; } public int Age { get; set; } } static class Program { static void Main(string[] ar... 阅读全文
posted @ 2012-05-16 14:19 清山博客 阅读(1211) 评论(2) 推荐(0)
摘要:用C#输出日历,此功能可用于Ajax方式列出计划日程相关的内容,由于是C#控制输出,可以方便加上自己需要的业务处理逻辑。1.控制台输出:using System; namespace 控制台日历 { class Program { public static void Main(string[] args) { string s = " "; Console.WriteLine("输入年份:"); int nYear = int.Parse(Console.ReadLine()); Console.WriteLine("输入月份:") 阅读全文
posted @ 2012-04-06 16:15 清山博客 阅读(2547) 评论(0) 推荐(0)
摘要:在开发过程中,经常会对xml,json,html数据打交道,查看这三类数据时,有一个快捷的格式化工具,往往能大大的提高效率。结合多方资源,本人写了个小工具,对这三类数据进行格式化,不废话了,贴图贴代码:程序界面:程序下载:http://download.csdn.net/detail/a497785609/4170938源码下载:http://download.csdn.net/detail/a497785609/41709471.Xml格式化:using System; using System.Collections.Generic; using System.Text; using .. 阅读全文
posted @ 2012-03-25 13:51 清山博客 阅读(3166) 评论(2) 推荐(0)
摘要:private string FormatXml(string sUnformattedXml) { XmlDocument xd = new XmlDocument(); xd.LoadXml(sUnformattedXml); StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); XmlTextWriter xtw = null; ... 阅读全文
posted @ 2012-03-23 17:06 清山博客 阅读(7146) 评论(1) 推荐(1)
摘要:原理很简单,解析程序集生成时的xml描述文档。设置生成程序集时生成xml描述文档的操作如下:程序界面:生成后的文档视图(样式调整需改源码)关键代码: /// <summary> /// 生成HTML说明文档 /// </summary> /// <param name="filePath">文件路径</param> public void GenneralHtmlDocument(string filePath) { XmlDocument doc = new XmlDocum... 阅读全文
posted @ 2012-03-22 17:27 清山博客 阅读(614) 评论(0) 推荐(0)