代码改变世界

随笔分类 -  C#

plugin framework 1

2013-03-13 23:07 by hongjiumu, 201 阅读, 收藏,
摘要: plugin framework 1http://msdn.microsoft.com/en-us/library/ms972962.aspxhttp://madskristensen.net/post/Generic-plug-in-application-in-C.aspx 阅读全文

oleDbCommand访问Excel

2013-03-02 18:17 by hongjiumu, 1428 阅读, 收藏,
摘要: oleDbCommand访问Excel:_oleCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$A2:A5]", _oleConn);objValue = _oleCmdSelect.ExecuteScalar();using System;using System.Collections.Generic;using System.Text; namespace ConsoleApplication1{ class Program { private static string _vsPath = @"Pro 阅读全文

Deleting specific rows from DataTable

2013-02-19 23:18 by hongjiumu, 179 阅读, 收藏,
摘要: Deleting specific rows from DataTablefor(inti = _vdtCurrentDataTable.Rows.Count-1; i >= 0;i-- ){if(_vdtCurrentDataTable.Rows[i]["Checked"].ToString() == "True")_vdtCurrentDataTable.Rows[i].Delete();} 阅读全文

(转).NET 一次查询多表,填充DataSet并指定表名(DataSet指定DataTable名称的技巧)

2013-02-19 23:17 by hongjiumu, 578 阅读, 收藏,
摘要: 现实中的场景,有时可能需要一次查询数据库中表张,在使用SqlDataAdapter类的Fill方法填充DataSet, 同时指定填充到DataSet中DataTable表名,例如设置成跟数据库一样的。可以通过SqlDataAdapter类的TableMappings属性实现。SqlDataAdapter类的Fill方法填充DataSet中表名称,默认是Table, Table1, Table2……SqlConnection conn=new SqlConnection("server=.; database=DataBaseName; uid=sa; pwd=sa"); / 阅读全文

T4生成实体类

2013-02-19 23:16 by hongjiumu, 205 阅读, 收藏,
摘要: <#@ template language="C#" debug="True" hostspecific="True" #> <#@ output extension=".cs" #> <#@ assembly name="System.Data" #> <#@ assembly name="System.xml" #> <#@ import namespace="System.Collections.Gener 阅读全文

如何:在派生类中引发基类事件

2013-01-06 00:06 by hongjiumu, 357 阅读, 收藏,
摘要: 如何:在派生类中引发基类事件http://msdn.microsoft.com/zh-cn/library/vstudio/hy3sefw3.aspx不要在基类中声明虚拟事件,也不要在派生类中重写这些事件。 C# 编译器无法正确处理这些事件,并且无法预知的该派生的事件的用户是否真正订阅了基类事件。using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace ConsoleApplication1{ public class Base { publ... 阅读全文

c#字定义异常处理类

2013-01-04 23:46 by hongjiumu, 235 阅读, 收藏,
摘要: public class DataLoaderException:Exception { private LogLevel _vLevel = LogLevel.None; private string _vsMessage = string.Empty; public LogLevel Level { get { return _vLevel; } } public string Message { get { return _vsMessa... 阅读全文

Thread并发数控制

2013-01-01 16:28 by hongjiumu, 864 阅读, 收藏,
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ public class LimitedConcurrencyLevelTaskScheduler : System.Threading.Tasks.TaskScheduler { #region Memeber Declarations /// <summary> /// Whether the current th... 阅读全文

simple workflow implement

2012-12-29 11:58 by hongjiumu, 143 阅读, 收藏,
摘要: 工作流简单实现http://www.codeproject.com/Articles/6947/Implementing-Object-Undo-and-Redo-capabilities-in 阅读全文

通过Assembly来创建Type Instance

2012-12-29 11:58 by hongjiumu, 507 阅读, 收藏,
摘要: 通过Assembly来创建Type Instance1,object obj=System.Reflection.Assembly.Load("assemblyname").CreateInstance("namespace.classname");//Assembly.Load takes a assembly name, not a file path(not include the tail of ".dll")ClassLib.User user=obj as ClassLib.User;Result:user is not 阅读全文

C#实现的不重复随机数序列生成算法

2012-12-24 23:29 by hongjiumu, 393 阅读, 收藏,
摘要: C#实现的不重复随机数序列生成算法http://www.ityoudao.com/Web/Csharp_590_1366.html 阅读全文

浅析c#中new、override、virtual关键字的区别

2012-10-30 23:56 by hongjiumu, 388 阅读, 收藏,
摘要: 最近简单的复习了在c#中涉及到继承这个特性时,所需要用到的关键字,其中有一些关键点,特地整理出来,方便大家查阅。在一次笔试和面试中也提到这个问题:一、在c#中,new这个关键字使用非常频繁,主要有3个功能:(1)作为运算符用来创建一个对象和调用构造函数;(2)作为修饰符;(3)用于在范型声明中约束可能用作类型参数的参数的类型在本文中,只具体介绍new作为修饰符的作用。用作修饰符时,new关键字可以在派生类中隐藏基类的方法。也就是说派生类调用的方法是new关键字新定义出来的方法,而不是基类的方法。在不使用new关键字来隐藏基类方法也是可以的,编译器会出现一个警告,提示如果有意隐藏基类的方法,请使 阅读全文

System.Threading中Thread和Task区别

2012-10-06 22:46 by hongjiumu, 2336 阅读, 收藏,
摘要: A task is something you want doing.A thread is one of possibly many workers who perform that task.In .NET 4.0 terms,a Task represents an asynchronous operation.Thread(s) are used to complete that operation by breaking the work up into chunks and assigning to seperate threads.Intel TBB and the OpenMP 阅读全文

匿名方法,Action,Func以及lambda的区别

2012-10-03 14:09 by hongjiumu, 1352 阅读, 收藏,
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace ConsoleApplication1{ public delegate int GetSum(object index); class Program { static void Main(string[] args) { /* ... 阅读全文

委托理解

2012-09-24 18:18 by hongjiumu, 272 阅读, 收藏,
摘要: 委托在本质上是一个类,我们用delegate关键字声明的所有委托都继承自System.MulticastDelegate。后者又继承自System.Delegate类,System.Delegate类则继承自System.Object。委托既然是一个类,那么它可以被定义在任何地方,既可以定义在类的内部,也可以定义在类的外部。正如很多资料上所说的,委托是一种类型安全的函数回调机制,它不仅能够调用实例方法,也能调用静态方法,并且具备按顺序执行多个方法的能力。由于委托继承自System.MulticastDelegate类,自然也继承MulticastDelegate类的字段、属性和方法。这些成员中 阅读全文

C#类型转换3

2012-09-15 16:57 by hongjiumu, 231 阅读, 收藏,
摘要: namespace WDBuyNET.DMSFrame.Utils{ public static class TypeExtentions { public static bool IsPrimitive(this Type t) { bool result; if (t.IsGenericType) { result = (TypeExtentions.IsNullableType(t) && TypeExtentions.IsPrimitive(Nulla... 阅读全文

C#类型转换2

2012-09-15 16:55 by hongjiumu, 322 阅读, 收藏,
摘要: namespace WDBuyNET.DMSFrame.Utils.Helpers{ public static class TypeHelper { public static object ChangeType(Type targetType, object val) { object result; if (val == null) { result = null; } else { ... 阅读全文

C#类型转换1

2012-09-15 16:52 by hongjiumu, 455 阅读, 收藏,
摘要: namespace WDBuyNET.DMSFrame.Utils.Helpers{ public static class ReflectionHelper { public class TypeLoadConfig { private bool copyToMemory; private bool loadAbstractType; private string targetFilePostfix; public bool CopyToMemory ... 阅读全文

List<T>.Contains(T item)为什么我把两封一样的邮件经分析后一模一样的数据mail_data先后导入进去,第2封信还是会加到mailList里去 ?? 搞不懂..

2012-09-10 15:48 by hongjiumu, 297 阅读, 收藏,
摘要: 方法1: static void Main(string[] args) { TestClass tc1 = new TestClass(); tc1.i = 1; TestClass tc2 = new TestClass(); tc2.i = 1; List<TestClass> list = new List<TestClass>(); list.Add(tc1); Console.WriteLine(lis... 阅读全文

一个可以生成复杂结构的json数据的简单例子

2012-09-08 17:53 by hongjiumu, 830 阅读, 收藏,
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Reflection;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { StringBuilder builder = new StringBuilder(); User user = new User("abc"... 阅读全文