我的疑问 - 关于C#静态构造函数
摘要:关于C#静态构造函数的资料,我找到的都是这样说的: 因为这个构造函数是属于类的,而不属于任何一个实例,所以这个构造函数只会被执行一次,而且是在创建此类的第一个实例或引用任何静态成员之前,由.NET自动调用。 1、静态构造函数既没有访问修饰符,也没有参数。 --因为是.NET调用的,所以像public和private等修饰符就没有意义了。 2、在创建第一个类实例或任何静态成员被引用时,...
阅读全文
posted @
2010-05-22 23:40
lantionzy
阅读(1981)
推荐(9)
C# notes (2)
摘要:一、扩展方法 有许多方法去扩展一个类,而如果没有源代码,怎么办?此时可以用扩喊方法,它允许改变一个类,但不需要类的源代码。扩展方法是静态方法,是类的一部分,尽管不在类的源代码中。比如,由于某种原因,程序集最初的源代码不能直接修改类TestClass,而又想为其添加一个NewMethod,此时可以创建一个静态类,把要添加的方法添加为静态方法。如:代码 Code highlighting produc...
阅读全文
posted @
2010-01-10 20:54
lantionzy
阅读(401)
推荐(1)
C# notes (1)
摘要:一、 C#静态字段与C#实例字段 C#的字段有静态字段和实例字段两种,字段进行的是引用传递,可以是任何类型。静态字段是属于类的,实例字段是属于对象的。如下:[代码] readonly关健字是用来声名一个只读字段的,也就是说字段是不充许被改写的,不过有个例外,在构造函数中,是可以对只读字段进行改写。二、var匿名类型和隐式类型变量 使用 隐式类型变量(Implicitly typed loca...
阅读全文
posted @
2010-01-07 18:20
lantionzy
阅读(341)
推荐(1)
使用Monitor类、Lock和Mutex类来同步多线程的执行
摘要:昨天在谈Singleton模式时,提到了多线程应用中有时会出现多个实例化的现象,需要进行线程同步 在多线程中,为了保持数据的同步,需要加锁,.NET Framework已经为我们提供了三个加锁的机制,分别是Monitor类、Lock关键字和Mutex类。 其中Lock关键词用法比较简单,Monitor类和Lock的用法差不多。这两个都是锁定数据或是锁定被调用的函数。而Mutex则多用于锁定多...
阅读全文
posted @
2010-01-03 18:16
lantionzy
阅读(599)
推荐(1)
Design Pattern学习(C#) ---- Singleton
摘要:Singleton模式: Singleton(单件或单态)模式是设计模式中比较简单而常用的模式。 有时候在整个应用程序中,会要求某个类有且只有一个实例,这个时候可以采用Singleton模式进行设计。用Singleton模式设计的类不仅能保证在应用中只有一个实例,而且提供了一种非全局变量的方法进行全局访问,称为全局访问点,这样对于没有全局变量概念的纯面向对象语言来说是非常方便的,比如C#。...
阅读全文
posted @
2010-01-02 16:49
lantionzy
阅读(613)
推荐(2)
Algorithm backup ---- Merge Sort(归并排序算法)
摘要:Merge sort is an O(n log n) comparison-based sorting algorithm. In most implementations it is stable, meaning that it preserves the input order of equal elements in the sorted output. It is an example...
阅读全文
posted @
2009-11-03 17:39
lantionzy
阅读(429)
推荐(1)
Algorithm backup ---- Heap Sort(堆排序算法)
摘要:Heapsort is acomparison-based sorting algorithm, and is part of the selection sort family. Although somewhat slower in practice on most machines than a good implementation ofquicksort, it has the adva...
阅读全文
posted @
2009-11-03 17:09
lantionzy
阅读(476)
推荐(1)
Algorithm backup ---- Selection sort(选择排序算法)
摘要:Selection sort is also asorting algorithm, specifically anin-place comparisonsort. It has O(n2) complexity, making it inefficient on large lists, and generally performs worse than the similarinsertion...
阅读全文
posted @
2009-11-03 16:35
lantionzy
阅读(262)
推荐(1)
Algorithm backup ---- Insertion Sort(插入排序算法)
摘要:Insertion sort is a simple sorting algorithm, a comparison sort in which the sorted array (or list) is built one entry at a time. It is much less efficient on large lists than more advanced algorithms...
阅读全文
posted @
2009-11-03 16:21
lantionzy
阅读(304)
推荐(1)
Algorithm backup ---- Compare occurences of each character of two strings(比较两个字符串每个字符出现频率是否一样)
摘要:Here are two strings, my task is to compare these two str1 and str2, and get if the occurences of each character of them are equal. As we know, we can get the ASCII code of a character, so I use an a...
阅读全文
posted @
2009-11-03 15:26
lantionzy
阅读(386)
推荐(1)
Algorithm backup ---- Find the kth largest number(寻找第K大数)
摘要:Here is a way to find the k-th largest number from an ayyay based on the theory of quick sort with an algorithmic complexity of O(n). First we find a base element from the array randomly, and then re...
阅读全文
posted @
2009-11-03 14:31
lantionzy
阅读(665)
推荐(1)
Algorithm backup ---- Quick Sort(快速排序算法)
摘要:The quick sort is an in-place, divide-and-conquer, massively recursive sort. Typically, quicksort is significantly faster in practice than other Θ(nlogn) algorithms, because its inner loop can be...
阅读全文
posted @
2009-11-03 13:26
lantionzy
阅读(355)
推荐(1)
Algorithm backup ---- Bubble Sort(冒泡排序算法)
摘要:The bubble sort is the oldest and simplest sort in use. Unfortunately, it's also the slowest. The bubble sort works by comparing each item in the list with the item next to it, and swapping them if ...
阅读全文
posted @
2009-11-03 10:32
lantionzy
阅读(386)
推荐(1)
That something between String and StringBuilder(String和StringBuilder之间的异同)
摘要:First, we take some time to have a look at these words: "The String object is immutable. Every time you use one of the methods in the System.String class, you create a new string object in memory, whi...
阅读全文
posted @
2009-11-01 17:16
lantionzy
阅读(266)
推荐(1)
Get data from specified URI using WebRequest and WebResponse(读取网页数据并存入对应html文档)
摘要:WebRequest is a request to send messages to a URI to send messages, URI as a parameter is passed to Create () method. And we take WebResponse class as data obtained from the server. The method WebRequ...
阅读全文
posted @
2009-10-30 18:18
lantionzy
阅读(316)
推荐(1)
VS2010 Code Intellisense Improvements(VS2010代码智能提示的改进)
摘要:This archive is from scott's blog http://weblogs.asp.net/scottgu To help illustrate this intellisense improvements coming with VS 2010, let’s start by doing a simple scenario in VS 2008 where...
阅读全文
posted @
2009-10-30 11:39
lantionzy
阅读(2512)
推荐(1)
Access Operation Using ADOX and OleDb(C#操作Access数据库)
摘要:Now, we are talking something aboutOffice Access(2007)operationusing C#. And I will show you how to create a access db file, including creating new table, insert and update data item. Before we start ...
阅读全文
posted @
2009-10-29 23:47
lantionzy
阅读(849)
推荐(1)
How to calculate Bowling Score(保龄球计分算法)
摘要:A game of ten-pin bowling is divided into ten rounds (called "frames"). In a frame, each player is given two opportunities to knock down the skittle targets (called "pins"). The player rolls the first...
阅读全文
posted @
2009-10-29 18:33
lantionzy
阅读(1310)
推荐(1)
The indexer in C#(C#中的索引器)
摘要:Indexers allow instances of a class or struct to be indexed just like arrays. Indexers resemblepropertiesexcept that their accessors take parameters.In the following example, a generic class is define...
阅读全文
posted @
2009-10-29 00:27
lantionzy
阅读(345)
推荐(0)
C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化
摘要:这两天整理了一下使用C#对word的操作,这里和大家分享: 1、新建Word文档[代码] 2、给word文档添加页眉页脚[代码] 3、设置文档格式并添加文本内容、超链接[代码] 4、添加图片[代码] 5、表格处理(插入表格、设置格式、填充内容、表格中加图片)[代码] 6、把Word文档转化为Html文件[代码]可以从这里下载整个类(包含更多内容)WordOperate cs file转...
阅读全文
posted @
2009-10-23 10:09
lantionzy
阅读(11459)
推荐(9)