C# v2.0 - Visual Studio 2005


These are most useful when used with container types such as lists, vectors, hash tables etc
Generics can treat the types that they contain specifically by their type rather than by using the object base type.
Allows you to create open-ended types that are converted to close types at runtime.


In C# you usually use foreach to iterate through a collection
This collection must implement the IEnumerable interface
This interface includes the GetEnumerator method which is often very tedious to implement
A new construct called an iterator block has been added to simplify this.
Collections > Iterators

Anonymous Methods

Anonymous methods allow you to define a delegate inline.
An anonymous method provides a way of passing a block of code as an argument instead of creating an explicit named method.
Use the delegate keyword to declare a delegate type first
A parameter is then passed to an anonymous method using the delegate keyword
no parameters

delegate void Delegate_Type(); 

Delegate_Type delegate_variable = delegate()
{ // do something }

instead of

delegate void Delegate_Type(); 

void Method_Name()
{ // do something }
Delegate_Type delegate_variable = Method_Name;

with a parameter

delegate int Delegate_Type(int x); 

Delegate_Type delegate_variable = delegate(int paramater)
{ return paremeter * parameter; }

instead of

delegate int Delegate_Type(int x); 

int Method_Name(int parameter)
{ return parameter * parameter; }
Delegate_Type delegate_variable = Method_Name;

Partial Classes

Prioir to C# 2.0 you had to define each class entirely in a single file
Automatically generated code can now live in a different file which prevents this code from being accidentally modified

Nullable Types

Data Types > Nullable Types

Known Bugs

The following line of code does not seem to work if you want to change the selected tab after the tab order has been fixed in the Form_Load event.

Me.tabWizard.SelectedIndex = 2 

This line of code seems to work though

Me.tabWizard.SelectedTab = Me.tabWizard.TabPages(2) 

VB.Net Specific

The default mechanism for passing arguments was changed from ByRef to ByVal
No longer need to use the Set keyword to initialise and set objects
Call is not required but is still supported for backwards compatibility

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext