![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
CSharp
albertliangyg
这个作者很懒,什么都没留下…
展开
-
面向对象的语言级实现
http://blog.csdn.net/chentaihan/article/details/7104776转载 2011-12-27 12:12:19 · 669 阅读 · 0 评论 -
关于 Equals与==
Albahari在书中已经说的非常好了,现在摘录如下:== and != The subtleties with == and != arise because they are operators, and so are statically resolved (in fact, they are implemented as static functions). So, when yo...转载 2019-02-21 11:31:13 · 269 阅读 · 0 评论 -
Convert vs Cast
Convert采用的是银行的舍入原则,而不是Cast的截取原则。Convert的四舍六入五留双规则:为了避免四舍五入规则造成的结果偏高,误差偏大的现象出现,一般采用四舍六入五留双规则(Banker's Rounding)。 四舍六入五留双应该改为: 四舍六入逢五无后则留双,这样描述更容易理解和记住.四舍六入五留双规则的具体方法是:(一)当尾数小于或等于4时,直接将尾数舍去。例...转载 2019-02-20 14:52:42 · 268 阅读 · 0 评论 -
Custom numeric format strings
string Multiplier="Multiplier:{0:#,}";Console.WriteLine (string.Format (Multiplier, 1000000));string LiteralChar = "LiteralChar={0:\\#000}";Console.WriteLine (string.Format (LiteralChar, 50));stri...转载 2019-02-20 09:54:57 · 121 阅读 · 0 评论 -
委托->匿名方法->Lambda表达式
1.委托:static void Main(){string[] names = { "Rodney", "Jack", "Jill" };string match = Array.Find (names, ContainsA);Console.WriteLine (match); // Jack}static bool ContainsA (string name) {retu...转载 2019-02-25 14:47:11 · 132 阅读 · 0 评论 -
Standard numeric format strings
string General = "General={0:G}";Console.WriteLine (string.Format (General, 0.00001));string FixedPoint="FixedPoint={0:F2}";Console.WriteLine (string.Format (FixedPoint, 2345.678));string WithGrou...转载 2019-02-20 09:16:06 · 166 阅读 · 0 评论 -
Covariant(协变) vs Contravariant(逆变)
public delegate TResult Func<in T, out TResult>(T arg);public interface IReadOnlyList<out T> : IEnumerable<T>, IEnumerable 任何能用父类做为输入参数的地方,当然也能用子类作为替换,这叫逆变(Contravariant)。任何返回...原创 2019-02-25 10:09:05 · 703 阅读 · 0 评论 -
集合类的自定义判等与比较
1)IComparer and Comparer:Comparers are used to switch in custom ordering logic for sorted dictionaries and collections.Note that a comparer is useless to the unsorted dictionaries such as Dic...原创 2019-02-28 15:10:47 · 157 阅读 · 0 评论 -
Delegate总结
关于Delegate已经写了很多,现总结如下。一) 一条线是观察delegate从.net framework 1.1 到目前为止4.5的变迁;例如如果你用delegate来模拟事件,你需要自己: // Add member to the invocation list. public void OnAboutToBlow(AboutToB原创 2013-09-26 11:28:01 · 603 阅读 · 0 评论 -
IEquatable<T>.Equals 是Object.Equals方法的泛型版本
The implementation of the Equals method is intended to perform a test for equality with another object of typeT, the same type as the current object. The Equals method is called in the following c原创 2013-02-27 10:44:33 · 1611 阅读 · 3 评论 -
IComparer<T> VS IComparable<T>
IComparer VS IComparable两者的比较其实是如何实现对象的custom sort 和default sort的过程。微软的MSDN上有一个sample很好的说明了这二者的区别与联系。//Main 函数: // Nested class to do descending sort on year property.private class sortYearDesc原创 2013-02-22 13:07:10 · 504 阅读 · 1 评论 -
IEqualityComparer<T> VS System.IEquatable<T>
类似于IComparer VS IComparable.public interface">IComparable<inT>{ // Methods <a title="System.Int32CTRL+Click to open in new tab." href="http://127.0.0.1/roeder/dotnet/Default.as原创 2013-02-26 17:34:53 · 1568 阅读 · 1 评论 -
KeyValuePair<TKey, TValue>是DictionaryEntry的泛型版本
如同Dictionary是HashTable的泛型版本一样,KeyValuePair是DictionaryEntry的泛型版本。Dictionary与HashTable内部是基于hash算法的,而SortedDictionary和SortedList是基于Red Black Tree(红黑树)的。DictionaryEntry: Hashtable openWith = new Has原创 2013-03-04 14:31:23 · 3303 阅读 · 3 评论 -
Subquery and Wrapping query
Subquery, Progressive query, Into, Wrapping query1. Using fluent syntaxstring[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" };IEnumerable outerQuery = names.Where (n => n.Length == names.O转载 2012-05-16 15:29:30 · 315 阅读 · 0 评论 -
Capturing iteration variables
首先要理解Lambda表达式的延迟执行(Deferred execution)An important feature of most query operators is that they execute not whenconstructed, but when enumerated.其次来理解捕获迭代变量When you capture iteration variable原创 2012-05-15 14:38:04 · 335 阅读 · 0 评论 -
Fluent syntax 与Query Expression syntax在LINQ中的应用
Fluent syntax IEnumerable filteredNames = names.Where (n => n.Contains ("a"));Query exppression syntax IEnumerable filteredNames = from n in names转载 2012-05-14 18:04:27 · 617 阅读 · 0 评论 -
Value object and Reference object
比较值对象与引用对象从存储区域来讲,值对象存储在stack中,而引用对象存储在heap中。从对象自身比较,值对象一般较小,而引用对象一般较大。判断是否相等的方法不同。原创 2011-12-22 16:04:52 · 399 阅读 · 0 评论 -
ToArray,CopyTo,List (IEnumerable<T> collection)
public class Stu{ public string Name{get;set;}}void Main(){List<Stu> list=new List<Stu>();list.Add(new Stu{Name="bert"});list.Add(new Stu{Name="david"});Stu[] r=new Stu[2];lis...原创 2019-02-27 09:23:35 · 357 阅读 · 0 评论