08 2013 档案

获取本机可用端口
摘要:如下:using System;using System.Collections.Generic;using System.Linq;using System.Net.NetworkInformation;namespace ConsoleApplication2{ public static class AvailablePort { /// public static int GetFirstAvailablePort() { const int MAX_PORT = 65535; cons... 阅读全文

posted @ 2013-08-14 20:07 yao2yao4 阅读(365) 评论(0) 推荐(0)

textbox的验证
摘要:代码如下:textBox1.KeyDown += (a, b) => { if (b.KeyCode == Keys.Enter) { textBox2.Focus(); } };textBox1.Leave += delegate { int result; if (!int.TryParse(textBox1.Text.Trim(), out result)) { MessageBox.Show("fsfd"); textB... 阅读全文

posted @ 2013-08-14 07:17 yao2yao4 阅读(298) 评论(0) 推荐(0)

鼠标和键盘操作的全局钩子库
摘要:注意只能用于AnyCPU、.NET版本一致、只能用于Winform。简化后的代码如下:using System;using System.ComponentModel;using System.Reflection;using System.Runtime.InteropServices;using System.Windows.Forms;namespace UserActivityMonitor{ /// /// This class monitors all mouse activities globally (also outside of the application... 阅读全文

posted @ 2013-08-14 06:46 yao2yao4 阅读(705) 评论(0) 推荐(0)

数码管图片
摘要:地址 阅读全文

posted @ 2013-08-12 21:04 yao2yao4 阅读(109) 评论(0) 推荐(0)

正则表达式
摘要:IP^(?!0.0.0.0)(?!255.255.255.255)((25[0-5]|2[0-4]\d|1\d\d|\d\d|\d)\.){3}(25[0-5]|2[0-4]\d|1\d\d|\d\d|\d)$子网掩码 ^(254|252|248|240|224|192|128|0)\.0\.0\.0$|^(255\.(254|252|248|240|224|192|128|0)\.0\.0)$|^(255\.255\.(254|252|248|240|224|192|128|0)\.0)$|^(255\.255\.255\.(254|252|248|240|224|192|128|0))$ 阅读全文

posted @ 2013-08-12 21:01 yao2yao4 阅读(243) 评论(0) 推荐(0)

ToString的格式化字符串
摘要:如下:var a = new TimeSpan(1, 2, 3).ToString(@"d\.hh\:mm\:ss");var b = DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss");var c = 12.ToString("0000");var d = 12.ToString("0.00");0.01:02:032013-08-12 20:08:48001212.00 阅读全文

posted @ 2013-08-12 20:10 yao2yao4 阅读(237) 评论(0) 推荐(0)

C# Builder
摘要:如下:class Program{ static void Main(string[] args) { var a = new Class1.Builder().BuildA(1).BuildB(2.1).BuildUp(); Console.Read(); }}public class Class1{ private Class1(Builder builder) { A = builder.A; B = builder.B; } internal int A { get; set; } ... 阅读全文

posted @ 2013-08-04 21:18 yao2yao4 阅读(196) 评论(0) 推荐(0)

获取附加在方法上的Attribute
摘要:如下:class Program{ static void Main(string[] args) { var methodInfo = typeof(Program).GetMethod("Function"); var a = methodInfo.CustomAttributes.First(w => w.AttributeType == typeof(BrowsableAttribute)); var b = (bool)(a.ConstructorArguments.First().Value); Console.R... 阅读全文

posted @ 2013-08-04 20:53 yao2yao4 阅读(262) 评论(0) 推荐(0)

用于创建实例的反射
摘要:如下:(int)Activator.CreateInstance(typeof(int));上面的int一般用接口来处理。该方法的参数是Type类型,而配置是string,所以建立string及其对应的Type的映射就很关键了。 阅读全文

posted @ 2013-08-04 19:56 yao2yao4 阅读(122) 评论(0) 推荐(0)

C# 简单工厂
摘要:如下:public static IList Create(Type type){ if (type == typeof(List)) { return new List(); } if (type == typeof(T[])) { return new T[0]; } throw new Exception();} 阅读全文

posted @ 2013-08-04 19:41 yao2yao4 阅读(93) 评论(0) 推荐(0)

C#单例模式
摘要:如下:sealed class Singleton{ Singleton() { } public static readonly Singleton Instance = new Singleton();} 阅读全文

posted @ 2013-08-04 18:33 yao2yao4 阅读(126) 评论(0) 推荐(0)

C#原型模式
摘要:如下:[Serializable]public class ModelNewTable : ICloneable{ public object Clone() { using (var stream = new MemoryStream()) { var formatter = new BinaryFormatter(); formatter.Serialize(stream, this); stream.Seek(0, SeekOrigin.Begin); retu... 阅读全文

posted @ 2013-08-04 18:32 yao2yao4 阅读(137) 评论(0) 推荐(0)

整洁代码清单
摘要:注释 去除可以在源代码控制系统中可以处理的注释 去除废弃的注释 去除冗余的注释 去除注释掉的代码函数 去除输出参数 去除布尔值参数 去除不会被使用的函数一般 去除重复 去除魔数 类和函数分离出职责 阅读全文

posted @ 2013-08-04 08:32 yao2yao4 阅读(140) 评论(0) 推荐(0)

Visual Studio快捷键设置
摘要:1、查看当前快捷键:环境-键盘-按快捷键2、文本编辑器-C#-显示-行号3、文本编辑器-C#-制表符-插入空格4、文本编辑器-所有语言-没有选定内容时对空行应用剪切或复制命令5、Ctrl+Shift-V 循环粘贴6、Ctrl+Shift-Enter 下开新行7、Ctrl+W 选中单词8、Ctrl+L 剪切当前行9、Ctrl+G 转到某行10、Ctrl+I Ctrl+Shift+I Esc 渐进式搜索 阅读全文

posted @ 2013-08-04 08:22 yao2yao4 阅读(459) 评论(0) 推荐(0)

异步读写锁
摘要:如下:ReaderWriterLockSlim 阅读全文

posted @ 2013-08-01 07:38 yao2yao4 阅读(148) 评论(0) 推荐(0)

同步方法
摘要:如下:[MethodImpl(MethodImplOptions.Synchronized)]public void Abc(){} 阅读全文

posted @ 2013-08-01 07:00 yao2yao4 阅读(132) 评论(0) 推荐(0)

导航