Day Dreaming

"A daydream is a visionary fantasy experienced while awake, especially one of happy, pleasant thoughts, hopes or ambitions."[Ref:Wikipedia]

Day 5: Chapter 12: Indexes, Operators and Pointers

This Chapter is relatively simple and deals with Indexes,Operators and Pointers.

Indexer Methods - In its simplest form, an indexer is created using the this[] syntax. You can use intergers or even string to represent indexers. For e.g. following gives a function to represent using strings – public Person this [string name] {get {} set {}} We can also overload indexer methods , can have them on interfaces and also have multi dimensional arrays.
Operator Overloading- You can perform operator overloading . E.g Overloading an addition operator for a class point with two variables can be done–
public static Point operator + (Point p1, Point p2)
You can overload all kinds of operator’s unary, binary or comparison and other operators.
Custom Conversions - Also consider conversion between two classes which do not have a same parent. In order to perform this we can use either implicit or explicit conversion. Declare a explicit conversion using the following syntax-
public static explicit operator
public static implicit operator
Working with pointers - When you wish to work with pointers in C#, you must specifically declare a block of “unsafe code” using the unsafe keyword. Once you have established an unsafe context, you are then free to build pointers to data types using the * operator and obtain the address of said pointer using the ‘&’ operator.

The rest of the chapter mainly deals with '->' operator,fixed,sizeof and preprocessor directives. These last concepts have already been done in C and hence I am not going into details.

0 comments: