GetHashCode()
摘要:【GetHashCode】 GetHashCode方法的默认实现不保证针对不同的对象返回唯一值。而且,.NET Framework 不保证GetHashCode方法的默认实现以及它所返回的值在不同版本的 .NET Framework 中是相同的。因此,在进行哈希运算时,该方法的默认实现不得用作唯一...
阅读全文
C# Equals
摘要:【C# Equals】1、Object.Equals() The type of comparison between the current instance and theobjparameter depends on whether the current instance is a ref...
阅读全文
C# ValueTypes
摘要:【C# ValueTypes】1、哪些类型是ValueType?The value types consist of two main categories:StructsEnumerationsStructs fall into these categories:Numeric typesInte...
阅读全文
boxing & unboxing
摘要:【boxing & unboxing】 Boxing is the process of converting avalue typeto the typeobjector to any interface type implemented by this value type.When the ...
阅读全文
C# params
摘要:【params】 By using theparamskeyword, you can specify amethod parameterthat takes a variable number of arguments. param是c#中的变长参数。 You can send a comm...
阅读全文
C#隐式类型局部变量&隐式类型数组
摘要:【隐式类型局部变量】 可以赋予局部变量推断“类型”var而不是显式类型。var关键字指示编译器根据初始化语句右侧的表达式推断变量的类型。推断类型可以是内置类型、匿名类型、用户定义类型或 .NET Framework 类库中定义的类型。 // i is compiled as an intvar ...
阅读全文
C#匿名类型 - Anonymous Types
摘要:【C#匿名类型 - Anonymous Types】 Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having ...
阅读全文
C#中实例Singleton
摘要:【C#中实例Singleton】1、经典方案:using System; public class Singleton { private static Singleton instance; private Singleton() {} public static Singlet...
阅读全文
System.Object
摘要:【System.Object】1、所有类均继承自System.Object,无论自定义类有无显式继承于System.Object。2、Object的GetType()实例方法用于获取一个类的类型对象System.Type。通过System.Type对象的Name方法,可以获取一个类的类名。 G...
阅读全文
C# Common Keyword II
摘要:【C# Common Keyword II】1、as运算符用于在兼容的引用类型之间执行某些类型的转换。 class csrefKeywordsOperators { class Base { public override string ToSt...
阅读全文
c# vs c++
摘要:【c# vs c++】1、在 C++ 中,类和结构实际上是相同的,而在 C# 中,它们很不一样。C# 类可以实现任意数量的接口,但只能从一个基类继承。而且,C# Struct不支持继承,也不支持显式默认构造函数(必须提供参数化构造函数)。 1)It is an error to define a ...
阅读全文
event & EventHandler
摘要:【event & EventHandler】 在老C#中EventHandler指的是一个需要定义一个delegate,这个delegate是回调的规范。例如:public delegate void CustomEventHandler(object sender, CustomEventArg...
阅读全文
IEnumerator & IEnumerable
摘要:【IEnumerator】 用于遍历一个对象,IEnumerator在System.Collections命名空间中。 public interface IEnumerator { object Current { get; ...
阅读全文
delegate
摘要:【delegate】 delegate定义了一个函数引用类型,犹如C++中的typedef,也犹如Objc中的Block(在捕获变量上有点差异)。 1、有名方法,delegate捕获的方法可以是实例方法或静态方法。 1 // Declare a delegate 2 delegate void ...
阅读全文
new 约束
摘要:【new 约束】 new约束指定泛型类声明中的任何类型参数都必须有公共的无参数构造函数。如果要使用 new 约束,则该类型不能为抽象类型。 当泛型类创建类型的新实例,请将new约束应用于类型参数,如下面的示例所示: 当与其他约束一起使用时,new()约束必须最后指定: 参考:http:/...
阅读全文
ref & out - C#中的参数传递
摘要:【ref & out -C#中的参数传递】 ref与out均指定函数参数按引用传递,惟一的不同是,ref传递的参数必须初始化,而out可以不用。 ref与out无法作为重载的依据,即ref与out编译器认为一样。如下: 但是ref函数与非ref函数是可以重载的,如下: To use ...
阅读全文
interface vs abstract
摘要:【interface vs abstract】1、interface中的方法不能用public、abstract修饰,interface中的方法只包括signature。 2、一个类只能继承一个abstract class,却可以实现多个interface。3、abstract class表示的是...
阅读全文
C#中的IEnumerator、foreach、yield
摘要:【C#中的IEnumerator、foreach、yield】1、IEnumerator,是一个接口,它的方法如下: 2、foreach语句,在编译后会变成IEnumerator的调用: 3、yield用于return一个IEnumerator。 参考:http://wenku.baidu.c...
阅读全文
C# Common Keyword
摘要:【C# Common Keyword】1、abstract Use theabstractmodifier in a class declaration to indicate that a class is intended only to be a base class of other cl...
阅读全文
C# Keynote
摘要:【C# Keynote】1、Main方法必须包含在一个类内,参数类型、返回值类型可以有多种变化。 1 // Hello1.cs 2 public class Hello1 3 { 4 public static void Main() 5 { 6 System.Console.WriteLine("Hello, World!"); 7 } 8 } 9 10 // Hello3.cs11 // arguments: A B C D12 using System;13 14 public class Hello315 {16 public static void...
阅读全文