Tuesday, January 30, 2007

Welcome in Part2 (Sorry it will be Long Post Coz it Will be the Final Part )Iteratorsallow you to easily create enumerable classes, classes that allow you to iterate through their collection of values through a foreach loop. Classes that implement the IEnumerable interface allow you to use foreach loop.To use IEnumerable interface we must implement GetEmumerator Method which return IEnumerator object which, this object allow foreach loop to work the way it does.The new iterator pattern makes use of the yield keyword , from this moment we don't have to create and implement an IEnumerable object , yield does all of this.Example : -If we tried to Store 100 000string in array of string then we tried to retrieve the array's values using foreach loop one by the old way and the second with the Yield Key word.Here is the difference with Yield it will take 93 milliseconds and with the Old Way 343milliseconds.

The Nullable Type Can Represent the Range of Value for any type plus it can hold the valuenull

Example : - Nullable can Hold Values in this Range from -2147483648 to2147483647 in addition to Null Value

another Example : - Nullable can hold The Value True or False ( false set as default in the normal Bool ) in addition to Null Value .

but what is its importance ?assume you are working in database applicationa Boolean field in a database can store the values true or false, or it may be undefined.

Syntax: -int? x = 10; or double? d = 4.108; ….. and so on

the most important Properties in nullable variables : -

The HasValue property returns true if the variable contains a value, or false if it is null.The Value property returns a value if one is assigned, otherwisea System.InvalidOperationException is thrown.

The last Thing to say aboutnullable Type that it can work onValue and Ref. Type.

Static Class

Static class was developed in c# 2.0 to prevent the problem of working with The classes which have Private constructors by using Reflection.Use The Keyword static in the declaration of the class to prevent the class instantiation byReflectionSyntax :-static class Class1

Anonymous Methods

Hint :- To understand Anonymous Methods you must understand Delegates Very Good. I will depend here that you Can use Delegates.

Earlier( in previous versions of C# ) we were handling the events like this

myButton.Click += new EventHandler(MyButton_OnClick);

public void MyButton_OnClick(object sender, EventArgs e){// do something}Here we first added a delegate to myButton’s Click event. The delegate is made to reference the MyButton_OnClick() method which is defined earlier.

Anonymous methodsallow you to define un-named methods ( any block of code )Like this

About us

We are a group of bloggers from Faculty of Computers & Information, Helwan University. We have a passion for technology, enjoy programming and we enjoy blogging. This blog is the result of combining those skills and the desire to share our knowledge with others.