随笔分类 -  C#

线程,任务,同步之Thread(二)
摘要:/*线程,任务,同步之Thread(二)*/using System;using System.Threading;using System.Diagnostics;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { /* //Thread t1 = new Thread(ThreadMethod); Thread t1 = new Thread(()=>{Console.WriteLine("2");});//使用Lambda表... 阅读全文

posted @ 2013-12-13 16:55 wp456 阅读(136) 评论(0) 推荐(0)

线程,任务,同步之Thread
摘要:/*线程,任务,同步之Thread*/using System;using System.Threading;using System.Diagnostics;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { //Thread t1 = new Thread(ThreadMethod); Thread t1 = new Thread(()=>{Console.WriteLine("2");});//使用Lambda表达式 t1.... 阅读全文

posted @ 2013-12-13 15:26 wp456 阅读(168) 评论(0) 推荐(0)

线程,任务,同步之异步回调
摘要:/*线程,任务,同步之异步回调*/using System;using System.Threading;using System.Diagnostics;namespace Frank{ public class Test { public delegate int TakesAWhileDelegate(int data,int ms); //程序入口 public static void Main(string[] args) { TakesAWhileDelegate dl = new TakesAWhileDelegate(TakesAWhi... 阅读全文

posted @ 2013-12-13 14:45 wp456 阅读(202) 评论(0) 推荐(0)

线程,任务,同步之异步执行和等待线程
摘要:/*线程,任务,同步之异步执行和等待线程*/using System;using System.Threading;namespace Frank{ public class Test { public delegate int TakesAWhileDelegate(int data,int ms); //程序入口 public static void Main(string[] args) { TakesAWhileDelegate dl = new TakesAWhileDelegate(TakesAWhile); IAsyncResult ... 阅读全文

posted @ 2013-12-13 14:21 wp456 阅读(366) 评论(0) 推荐(0)

反射基础一
摘要:/*反射*/using System;using System.Reflection;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { Type intType = typeof(int); System.Console.WriteLine(intType.IsAbstract); System.Console.WriteLine(intType.IsClass); System.Console.WriteLine(intT... 阅读全文

posted @ 2013-12-12 11:02 wp456 阅读(143) 评论(0) 推荐(0)

自定义特性
摘要:/*自定义特性*/using System;namespace Frank{ public class Test { [FileName("Name")] public string Name {get;set;} //程序入口 public static void Main(string[] args) { Test t = new Test(); t.Name="1"; } } //AllowMultiple 表示一个地方是否可以重复使用属性 //Inherited 表示是否可以应用到派生类 //AttributeTargets 是一个枚举... 阅读全文

posted @ 2013-12-11 16:17 wp456 阅读(147) 评论(0) 推荐(0)

内存管理与指针
摘要:/*内存管理与指针每隔一段时间GC会自动执行清理,也可以程序调用。清理的时候会执行终结器,然后清理,也可以调用超级清理告诉GC不用调用终结器。*/using System.Collections.Generic;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { unsafe { int x = 10; int* pX,pY; pX = & x;//取址符号 pY = pX; *pY = 20;//反向取... 阅读全文

posted @ 2013-12-11 09:06 wp456 阅读(143) 评论(0) 推荐(0)

集(Set)
摘要:/*集(Set).Net4包含两个HashSet 和 SortedSetHashSet包含不重复元素的无序列表,SortedSet包含不重复元素的有序集合*/using System.Collections.Generic;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { HashSet hs1 = new HashSet(); hs1.Add("wuhan"); System.Console.WriteLine(hs1.Add... 阅读全文

posted @ 2013-12-07 10:19 wp456 阅读(253) 评论(0) 推荐(0)

有序字典
摘要:/*有序字典SortedDictionary类的使用,它是一个二叉搜索树它比SortedList的元素插入和删除速度比较快。SortedList的内存比它占用的要少,在已排序的数据填充集合时SortedList要快。*/using System.Collections.Generic;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { SortedDictionary sd = new SortedDictionary(); sd.A... 阅读全文

posted @ 2013-12-06 15:21 wp456 阅读(170) 评论(0) 推荐(0)

Lookup类的使用
摘要:/*Lookup类的使用 一键多值*/using System.Linq;using System.Collections.Generic;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { List list = new List(); list.Add(new Racer("jack","wuhan")); list.Add(new Racer("tom","wuhan")); list.Add 阅读全文

posted @ 2013-12-06 14:43 wp456 阅读(259) 评论(0) 推荐(0)

字典Dictionary
摘要:/*字典Dictionary (映射或者散列表)键值对的,如果把一个自定义类型作为字典的键,那么必须重写GetHashCode和Equals方法string类就实现了,一般用string类型的最为键*/using System.Collections.Generic;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { Dictionary d = new Dictionary(); d.Add("1","a"); d.Add(" 阅读全文

posted @ 2013-12-05 14:58 wp456 阅读(130) 评论(0) 推荐(0)

有序列表
摘要:/*有序列表键值对的表示一个键只能有一个值,如果需要多个值,使用Lookup类*/using System.Collections.Generic;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { SortedList books = new SortedList(); books.Add("1","2sad"); books.Add("2","sadsad"); books["3&qu 阅读全文

posted @ 2013-12-05 11:49 wp456 阅读(146) 评论(0) 推荐(0)

双向链表
摘要:/*双向链表放入元素速度十分的快。*/using System.Collections.Generic;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { LinkedListNode ln = new LinkedListNode("c"); LinkedList ll = new LinkedList(); ll.AddLast("a"); ll.AddLast("b"); ll.AddLast(ln); for. 阅读全文

posted @ 2013-12-05 11:38 wp456 阅读(102) 评论(0) 推荐(0)

栈,后进先出
摘要:/*栈,后进先出*/using System.Collections.Generic;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { Stack stack = new Stack(); stack.Push(1); stack.Push(5); stack.Push(6); stack.Push(7); foreach (int item in stack) { System.Console.Write... 阅读全文

posted @ 2013-12-05 10:42 wp456 阅读(322) 评论(0) 推荐(0)

队列的使用 先进先出的原则
摘要:/*队列的使用 先进先出的原则*/using System.Threading;using System.Collections.Generic;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { DocumentManager dm = new DocumentManager(); ProcessDocuments.Start(dm); for(int i = 0;i documentQueue = new Queue(); ... 阅读全文

posted @ 2013-12-05 10:30 wp456 阅读(542) 评论(0) 推荐(0)

正则表达式的使用
摘要:/*正则表达式的使用*/using System.Text.RegularExpressions;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { const string myText = "abcdeafsgabcadefgaaabcdefagaabcdefgaa"; string pattern = "a"; MatchCollection myMatches = Regex.Matches(myText,pattern... 阅读全文

posted @ 2013-11-30 16:20 wp456 阅读(178) 评论(0) 推荐(0)

string类和StringBuilder格式化的使用
摘要:/*string类和StringBuilder格式化的使用*/using System;using System.Text;namespace Frank{ public class Test { //程序入口 public static void Main(string[] args) { //string类是一个不可变的类,如果对一个string类型的变量进行多少的修改应该使用StringBuilder类,因为后者比前者速度更快,更节省空间 string str = "1"; str += "2"; StringBuilder SB = ... 阅读全文

posted @ 2013-11-30 15:02 wp456 阅读(793) 评论(0) 推荐(0)

弱事件模式(WPF里面就使用了弱事件模式)
摘要:/*弱事件直接连接发布程序和侦听器如果发布器不在连接侦听器的话垃圾回收不能清空侦听器。这种强连接可以通过弱事件模式来解决。*/using System;using System.Windows;namespace Frank{ public class WeakCarInfoEventManager : WeakEventManager { /// ///添加监听 /// public static void AddListener(object source,IWeakEventListener listener) { CurrentMangeager.ProtectedAdd... 阅读全文

posted @ 2013-11-30 13:37 wp456 阅读(306) 评论(0) 推荐(0)

事件
摘要:/*事件定义事件需要用委托类型的去声明一个事件。*/using System;namespace Frank{ public class Test { public delegate string Get(string x);//自定义委托 //简写模式的事件 public event Get NewEvent;//自从有了EventHandler泛型委托后就在也不需要自己定义委托了。它有两个参数,第一个是调用者,第二个是T类型。还定义了约束。 //完整模式的事件定义,类似于属性和字段。编译器自动的添加的。 /* public event Get NewEvent2 { ... 阅读全文

posted @ 2013-11-29 16:54 wp456 阅读(207) 评论(0) 推荐(0)

匿名方法和Lambda表达式的使用
摘要:/*匿名方法和Lambda表达式的使用*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { string mid = ", middle part,"; Func anonDel = delegate(string param)//创建匿名方法交给委托 { param += mid; param += " and this was added to the string."; return param... 阅读全文

posted @ 2013-11-29 14:07 wp456 阅读(167) 评论(0) 推荐(0)

导航