OPERATOR OVERLOAD methods are not part of the Common Language Specification.
EVENTS - used to send notification to a listening type or a listening object.
Attributes for Types
* Abstract - abstract - MustInherit
* Sealed - sealed - NotInheritable
Use of Sealed and private constructor - when creating your own type that contains only static members.
Attributes for fields
* Static - static - Shared - allocated when class loads - first time it is JIT compiled.
* InitOnly - readonly - ReadOnly - The field can be written to only by code contained in a construtor method.
Method Predifined attributes
* Static - Static - Shared - can't access instance fields or methods defined within the type.
* Virtual - virtual - Overridable - default type - applies only to non static methods
* Newslot - new - shadows - default type - should not override a virtual method of base and hides the inherited method. applies only to virtual methods.
* Abstract - abstract - MustOverride - must be implemented by derived type. applies only to virtual methods.
* Override - override - Overrides - explicitly states that the method is overiding virtual method of base.
* Final - sealed - NotOverridable - Cant be override. applies only to virtual method
Constants -
* saves value in metadata determined at compile time -
* applies only to primitive types -
* part of type - implicity static
* cant be passed by reference
Create a constant at run time use - public static readonly int32 value = 50
Creation of ref type object - all fields are zeroed out then constructor is called.
Create a instance of a type without calling its constructor - Use memberwiseclone method or deserialize an object
Value type constructor -
* C# doesnt allow parameterless constructot but CLR allows
* Constructor must initialize all the type fields otherwise complile time error.
Type Constructors or static constructors -
* should be marked as static
* always implicitly private
* parameterless
* CLR is responsible to call type constructor
* will never call base constructor or fields
* static fields are never inherited or shared
reference type passing by value - new ref type created and pointing to the same object
reference type passing by ref or out- same ref type copied.
Variables passed by reference to a method must be the same type. This is to ensure the type safety so type casting doesnt happen.
Variable parameter
* should always be the last parameter
* even pass null or no parameter to param
static void Main(string[] str)
{
variableparam("saurabh", true, 1, 2, 3, 4, 4, 4);
variableparam("no param", false);
Console.Read();
}
static void variableparam(string a, Boolean b,params int[] c)
{
Console.WriteLine("a={0}, b={1}, c={2} ", a, b,c[2]);
}
Properties
* smart fields
* static, instance and virtual properties
* defined within an interface
* overload not possible
* readonly - set method is absent
* writeonly - get method is absent
* C# calls it indexers and vb defalult properties
* indexers can have atleast one or more than one parameters
* C# indexers only on instance of objects - no static indexers but CLR does.
* indexers is kind of overloading of [] operator
Monday, December 8, 2008
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment