.NET Technical bits: November 2010

Tuesday, November 30, 2010

Difference Between .net 2.0,3.0,3.5

.NET Framework 2.0
Released with Visual Studio 2005 , Microsoft SQL Server 2005, and BizTalk 2006.
The 2.0 Redistributable Package can be downloaded for free from Microsoft, and was published on 2006-01-22.
The 2.0 Software Development Kit (SDK) can be downloaded for free from Microsoft.
It is included as part of Visual Studio 2005 and Microsoft SQL Server 2005.
Version 2.0 is the last version with support for Windows 2000, Windows 98 and Windows Me.
It shipped with Windows Server 2003 R2 (not installed by default).
Changes in 2.0 on comparison with 1.1
Numerous API changes.
A new hosting API for native applications wishing to host an instance of the .NET runtime. The new API gives a fine grain control on the behavior of the runtime with regards to multithreading, memory allocation, assembly loading and more (detailed reference). It was initially developed to efficiently host the runtime in Microsoft SQL Server, which implements its own scheduler and memory manager.
Full 64-bit support for both the x64 and the IA64 hardware platforms.
Language support for generics built directly into the .NET CLR.
Many additional and improved ASP.NET web controls.
New data controls with declarative data binding.
New personalization features for ASP.NET, such as support for themes, skins and webparts.
.NET Micro Framework - a version of the .NET Framework related to the Smart Personal Objects Technology initiative.
Partial classes
Anonymous methods
.NET Framework 3.0
.NET Framework 3.0, formerly called WinFX includes a new set of managed code APIs that are an integral part of Windows Vista and Windows Server 2008 operating systems. It is also available for Windows XP SP2 and Windows Server 2003 as a download. There are no major architectural changes included with this release; .NET Framework 3.0 uses the Common Language Runtime of .NET Framework 2.0 Unlike the previous major .NET releases there was no .NET Compact Framework release made as a counterpart of this version.
.NET Framework 3.0 consists of four major new components:
Windows Presentation Foundation (WPF), formerly code-named Avalon; a new user interface subsystem and API based on XML and vector graphics, which uses 3D computer graphics hardware and Direct3D technologies. See WPF SDK for developer articles and documentation on WPF.
Windows Communication Foundation (WCF), formerly code-named Indigo; a service-oriented messaging system which allows programs to interoperate locally or remotely similar to web services.
Windows Workflow Foundation (WF) allows for building of task automation and integrated transactions using workflows.
Windows CardSpace, formerly code-named InfoCard; a software component which securely stores a person's digital identities and provides a unified interface for choosing the identity for a particular transaction, such as logging in to a website.
.NET Framework 3.5
Version 3.5 of the .NET Framework was released on 19 November 2007, but it is not included with Windows Server 2008. As with .NET Framework 3.0, version 3.5 uses the CLR of version 2.0. In addition, it installs .NET Framework 2.0 SP1, .NET Framework 2.0 SP2 (with 3.5 SP1) and .NET Framework 3.0 SP1, which adds some methods and properties to the BCL classes in version 2.0 which are required for version 3.5 features such as Language Integrated Query (LINQ). These changes do not affect applications written for version 2.0, however As with previous versions, a new .NET Compact Framework 3.5 was released in tandem with this update in order to provide support for additional features on Windows Mobile and Windows Embedded CE devices.
The source code of the Base Class Library in this version has been partially released (for debugging reference only) under the Microsoft Reference Source License.
Changes since version 3.0
New language features in C# 3.0 and VB.NET 9.0 compiler
Adds support for expression trees and lambda methods
Extension methods
Expression trees to represent high-level source code at runtime
Anonymous types with static type inference
Language Integrated Query (LINQ) along with its various providers
LINQ to Objects
LINQ to XML
LINQ to SQL
Paging support for ADO.NET
ADO.NET synchronization API to synchronize local caches and server side datastores
Asynchronous network I/O API
Peer-to-peer networking stack, including a managed PNRP resolver
Managed wrappers for Windows Management Instrumentation and Active Directory APIs
Enhanced WCF and WF runtimes, which let WCF work with POX and JSON data, and also expose WF workflows as WCF services.WCF services can be made stateful using the WF persistence model.
Support for HTTP pipelining and syndication feeds.
ASP.NET AJAX is included
New System.CodeDom namespace.

Difference between ArrayList and Generic List

Here we will see some important differences for the collections ArrayList() and Generic List

ArrayList:

  • The namespace for ArrayList is System.Collections

  • How to create ArrayList?


    ArrayList stringArrayList = new ArrayList();

    Here we dont need to specify object type arraylist going to contain,store different type of objects or items



  • In ArrayList each item is stored as an Object so while reteriving we can get object only.

  • It is like Array of Objects.


Generic List:

  • The namespace for Generic List is System.Collections.Generic

  • How to create a List?


    List stringList = new List();

    i.e.


    List<type> nameOfList = new List<type>();


    type means object type which List<T> going to hold.



  • In List<T> , it can hold or contain only type of object which is mentioned while initialising the List<T>
    Just like in above example stringList will only contain object of type string, the type supplied as generic parameter.


  • It is newly added in .Net 2.0 and onwards, processing will be fast and no need of explicit casting.



Let us see one example.

string first = “First String”;

string second = “Second String”;

int firstInt = 1;

int secondInt = 2;

ArrayList stringArrayList = new ArrayList(); // No need to specify the object type,can store anything.

stringArrayList.Add(first); // string type

stringArrayList.Add(second); // string type

stringArrayList.Add(firstInt); // Can contain any type so no problem in storing int


List stringList = new List(); // Need to specify the object type, will contain only string types.

stringList.Add(first);

stringList.Add(second);


See this sample

stringList.Add(firstInt); // adding int in string type List.


we will get the exceptions below as List need to contain only string types. others are not allowed.


1) ‘The best overloaded method match for ‘System.Collections.Generic.List.Add(string)’ has some invalid arguments’

2) ‘Argument ’1′: cannot convert from ‘int’ to ‘string’


See another Sample


string abcd = stringArrayList[1];


Suppose if we try to get an ArrayList item without using the casting then we can get following exception, as arraylist contain Objects only we need to cast as pre our requirments.

We will get Exception –


‘Cannot implicitly convert type ‘object’ to ‘string’. An explicit conversion exists (are you missing a cast?)’


We can avoid it as


string abcd = stringArrayList[1].ToString(); // Needs casting ,memory overhead.