C#/.Net
chuwachen
这个作者很懒,什么都没留下…
展开
-
C#中调用dll(托管和非托管)的方法
<br />1. 如果C#调用托管dll(比如C#生成的dll),可以使用下面的两个方法:<br />(1)通过project--->Add Reference--->Browser--->选择要加入的dll,同时将dll中要使用的变量或函数的所属的namespace加进来(using xxxx;).<br />(2)通过project--->Add Reference--->Projects将dll所在的project加进来即可。<br />2. 如果C#调用非托管的dll(比如 unmanaged C+原创 2011-01-13 11:27:00 · 2789 阅读 · 3 评论 -
Conversion between json and object
public static string ObjToJson(T obj) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); string retVal = Constant.strNullString;原创 2013-08-20 14:28:28 · 927 阅读 · 0 评论 -
Solution for "De-serialization exception: Unable to find assembly xxxxx"
public static object DeSerialize(string fileName) { BinaryFormatter formatter = new BinaryFormatter(); // *** Force Assembly resolving code to fire so we can load the assemb原创 2013-08-22 15:03:27 · 1132 阅读 · 0 评论 -
Serialize and Deserialize
If a class only has variables that already support serialize/deserialize such as string, int, and etc, we just need add the attribute [Serializabe] to the class. If a class has static variables, it ne原创 2012-12-20 17:52:35 · 3719 阅读 · 0 评论 -
Using Spring.net in console application
Download Spring.net in http://www.springframework.net/Install Spring.NET.exeCreate a console application, and reference Spring.Core.dll.Add App.config to project, the content is as f转载 2013-09-03 18:29:37 · 757 阅读 · 0 评论 -
Task Parallelism
The Task Parallel Library (TPL) is based on the concept of a task, which represents an asynchronous operation. In some ways, a task resembles a thread or ThreadPool work item, but at a higher level转载 2013-12-19 15:42:16 · 1051 阅读 · 0 评论 -
Async Return Types
Async methods have three possible return types: TaskTResult>, Task, and void.The TaskTResult> return type is used for an async method that contains a return (C#) statement in which the opera转载 2013-12-19 16:14:00 · 671 阅读 · 0 评论 -
Different timers in .net
Multi-threads timers: System.Threading.Timer and System.Timers.Timer (.net framework):App will handle timer event on a thread pool thread. Timers.Timer is a wrapper for Threading.Timer. They are use原创 2014-01-07 11:52:46 · 667 阅读 · 0 评论 -
.NET深入解析LINQ框架
转载自http://www.cnblogs.com/wangiqngpei557/archive/2012/11/10/2764201.html转载 2014-07-07 12:40:20 · 1092 阅读 · 0 评论 -
CLR内存管理
CLR管理内存的区域,主要有三块,分别为:1.线程的堆栈:(在程序应该编译过程为值类型实例分配好内存)用于分配值类型实例。堆栈主要由操作系统管理,而不受垃圾收集器的控制,当值类型实例所在方法结束时,其存储单位自动释放。栈的执行效率高,但存储容量有限。对于值类型来说,一般创建在线程的堆栈上。但并非所有的值类型都创建在线程的堆栈上,例如作为类的字段时,值类型作为实例成员的一部分转载 2014-07-18 16:49:00 · 772 阅读 · 0 评论 -
传递引用类型参数(ref)
引用类型的变量不直接包含其数据;它包含的是对其数据的引用。 当通过值传递引用类型的参数时,有可能更改引用所指向的数据,如某类成员的值。 但是无法更改引用本身的值;也就是说,不能使用相同的引用为新类分配内存并使之在块外保持。 若要这样做,应使用 ref 或 out 关键字传递参数。转载 2014-07-18 17:00:13 · 1519 阅读 · 0 评论 -
Static Constructors
A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or转载 2014-07-07 18:17:53 · 660 阅读 · 0 评论 -
Modifiers: virtual, override, new, abstract, sealed, internal
internal声明类、类成员、接口或接口成员具有内部可见性。internal 修饰符使类、接口或成员仅在当前包中可见。 当前包之外的代码不能访问 internal 成员。只有在同一程序集的文件中,内部类型或成员才是可访问的在全局范围内,internal 修饰符与 public 修饰符相同。不能将 internal 修饰符与其他任何可见性修饰符(public、private 或原创 2014-07-11 11:45:32 · 1350 阅读 · 0 评论 -
static, readonly, const
staticUse the static modifier to declare a static member, which belongs to the type itself rather than to a specific object. The static modifier can be used with classes, fields, methods, proper原创 2014-07-11 12:34:26 · 1080 阅读 · 0 评论 -
How to create Web Deployment Package and install the package
Create Web Deployment Package转载 2014-08-11 17:43:47 · 706 阅读 · 0 评论 -
Some string utilities
// Removes special characters from a stringpublic string RemoveSpecialChars(string input, string specialChars){ return Regex.Replace(input, specialChars, string.Empty);}// Reverses a stringp原创 2013-06-06 12:01:18 · 1087 阅读 · 0 评论 -
Encrypt/decrypt when serialize/deserialize data
private byte[] salt = ASCIIEncoding.ASCII.GetBytes("SaltString"); private const int DESKeySize = 8; // The key for DES must be 8 bytes. /// /// Generates a Rfc key. /// /// The string u原创 2013-06-06 11:50:45 · 998 阅读 · 0 评论 -
managed code和unmanaged code混合debug
首先:1. managed code的项目属性中debug页里,"Enable unmanaged code debugging"选上。2. unmanaged code项目属性的debug页里,Debugger Type设为Mixed。其次:原创 2011-09-20 13:21:02 · 3514 阅读 · 0 评论 -
C#如何调用c++静态库(lib)
可以用CLR(新)或者Managed c++(老)将lib封装成managed dll供C#直接调用。将lib封装成native dll,C#中通过DllImport调用dll。将lib封装成native dll, 再用CLR封装native dll成managed dll供C#直接调用。将lib封装为COM,在C#中调用COM。原创 2011-09-21 14:01:10 · 34189 阅读 · 8 评论 -
值类型 引用类型 ref out
值类型主要由两类组成:结构和枚举。结构分为以下几类:Numeric(数值)类型 (整型 浮点型 decimal)bool 用户定义的结构。基于值类型的变量直接包含值。将一个值类型变量赋给另一个值类型变量时,将复制包含的值。这与引用类型变量的赋值不同,引用类型变量的赋值只复制对对象的引用,而不复制对象本身。引用类型的变量又称为对象,可存储对实际数据的引用。包括:class interface del原创 2012-03-31 16:41:42 · 1913 阅读 · 0 评论 -
Check if the name and password are correct for domain
PrincipalContext context = new PrincipalContext(ContextType.Domain); bool isValid = context.ValidateCredentials(userName, password);原创 2012-11-12 16:58:17 · 802 阅读 · 0 评论 -
How to find exchange server users
How to find exchange server users? DirectoryEntry entry = new DirectoryEntry(_ldap, userName, password); // _ldap is domain such as "LDAP://xxx.xxx.com"; DirectorySearcher ds = ne原创 2012-11-12 16:54:27 · 439 阅读 · 0 评论 -
Invoke vs BeginInvoke
Control的Invoke和BeginInvoke:Control.Invoke 方法 (Delegate) :在拥有此控件的基础窗口句柄的线程(UI thread)上执行指定的委托。Control.BeginInvoke 方法 (Delegate) :在创建控件的基础句柄所在线程(UI thread)上异步执行指定委托。Control的Invoke和BeginInvoke的参数原创 2012-11-12 18:44:36 · 693 阅读 · 0 评论 -
Path File URI
How to convert between URI and normal file path:Convert normal file path to URI: Uri uri = new Uri(@"c:\Documents\myfile");Convert URI to normal file path: string normalPath = new Uri(uriPath).Loc原创 2013-01-30 14:12:21 · 1085 阅读 · 0 评论 -
Delegate
A delegate is a type that safely encapsulates a method, similar to a function pointer in C and C++. Unlike C function pointers, delegates are object-oriented, type safe, and secure. The type of a de原创 2013-02-01 15:55:39 · 859 阅读 · 0 评论 -
When to Use Delegates Instead of Interfaces
Both delegates and interfaces enable a class designer to separate type declarations and implementation. A given interface can be inherited and implemented by any class or struct. A delegate can be c转载 2013-02-01 17:10:09 · 431 阅读 · 0 评论 -
Event
Multicast delegates are used extensively in event handling. Event source objects send event notifications to recipient objects that have registered to receive that event. To register for an event, t原创 2013-02-02 15:46:21 · 739 阅读 · 0 评论 -
二维码生成与解析 (使用ThoughtWorks.QRCode)
二维码生成QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; // support different modeqrCodeEncoder.QRCodeScale = 1;qrCodeEncoder.原创 2013-02-04 12:24:34 · 13094 阅读 · 0 评论 -
Dispatcher
Dispatcher 可为特定线程维护其按优先顺序排列的工作项队列。当在线程中创建了 Dispatcher 时,它将成为可与该线程关联的唯一 Dispatcher,即使 Dispatcher 已经关闭。如果尝试获取当前线程的 CurrentDispatcher,而此时该线程没有关联的 Dispatcher,则将创建一个Dispatcher。A Dispatcher在创建时还创建Dispatcher原创 2013-02-16 11:13:07 · 1091 阅读 · 0 评论 -
How to add nested MenuItem dynamically
How to add sub items to "Second Item" dynamicallyIn xaml file // Initialize context menu event Second原创 2013-02-16 18:51:58 · 571 阅读 · 0 评论 -
Get machine IP and location via open api private static string GetOwnPublicIP() {
private static string GetOwnPublicIP() { try { var html = new WebClient().DownloadString( "http://checkip.dyndns.com/"); var ipStart = html.IndexOf(": "原创 2013-03-25 16:58:39 · 889 阅读 · 0 评论 -
值类型,引用类型,装箱,拆箱
装箱是将值类型转换为 object 类型或由此值类型实现的任何接口类型的过程。 当 CLR 对值类型进行装箱时,会将该值包装到 System.Object 内部,再将后者存储在托管堆上。 取消装箱将从对象中提取值类型。 装箱是隐式的;取消装箱是显式的。 装箱和取消装箱的概念是类型系统 C# 统一视图的基础,其中任一类型的值都被视为一个对象。原创 2014-07-15 15:23:54 · 1840 阅读 · 0 评论