Thursday, 9 August 2012

NET framework Comparison

NET framework Comparison
NET framework 2.0: 

It brings a lot of evolution in class of the framework and refactor control including the support of

  • Generics
  • Anonymous methods
  • Partial class
  • Nullable type
  • The new API gives a fine grain control on the behavior of the runtime with regards to multithreading, memory allocation, assembly loading and more
  • Full 64-bit support for both the x64 and the IA64 hardware platforms
  • New personalization features for ASP.NET, such as support for themes, skins and webparts.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 framework 3.0: 

  • Also called WinFX,includes a new set of managed code APIs that are an integral part of Windows Vista and Windows Server 2008 operating systems and provides
  • Windows Presentation Foundation (WPF), formerly code-named Avalon; a new user interface subsystem and API based on XML and vector graphics, which will make use of 3D computer graphics hardware and Direct3D technologies.
  • 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 (WWF) allows for building of task automation and integrated transactions using workflows.
  • Windows Workflow Foundation (WF) allows for building of task automation and integrated transactions using workflows.
  • Windows CardSpace, formerly called 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
  • Windows CardSpace (WCS), 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.0:

  • Also called WinFX,includes a new set of managed code APIs that are an integral part of Windows Vista and Windows Server 2008 operating systems and provides
  • Windows Communication Foundation (WCF), formerly called Indigo; a service-oriented messaging system which allows programs to interoperate locally or remotely similar to web services.
  • Windows Presentation Foundation (WPF), formerly called Avalon; a new user interface subsystem and API based on XML and vector graphics, which uses 3D computer graphics hardware and Direct3D technologies.
  • Windows Workflow Foundation (WF) allows for building of task automation and integrated transactions using workflows.
  • Windows CardSpace, formerly called 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:
It implement Linq evolution in language. So we have the folowing evolution in class:

  • Linq for SQL, XML, Dataset, Object
  • Addin system
  • p2p base class
  • Active directory
  • ASP.NET Ajax
  • Anonymous types with static type inference
  • Paging support for ADO.NET
  • ADO.NET synchronization API to synchronize local caches and server side datastores
  • Asynchronous network I/O API
  • Support for HTTP pipelining and syndication feeds.
  • New System.CodeDom namespace.

Sealed Class In C#

In C#, the sealed modifier is used to define a class as sealed. In Visual Basic .NET, NotInheritable keyword serves the purpose of sealed. If a class is derived from a sealed class, compiler throws an error.

Ex:
     // Sealed class
     sealed class clsSealedClass
    {   
    }

·   But if you try to use this class as a base class you will get error.
    
     // Error will generate
     sealed class clsMyClass: clsSealedClass
    {   
    }

·   This example demonstrate how to use the sealed class

    using System;
    class clsMyClass
    {
        static void Main()
        {
            clsSealedClass oclsSealedClass = new clsSealedClass ();
            int total = oclsSealedClass.Add(45);
            Console.WriteLine("Total = " + total.ToString());
       }
    }

    // Sealed class
    sealed class clsSealedClass
    {
        public int Add(int x, int y)
        {
             return x + y;
         }
     }

Abstract Class In C#

·   Class cannot be instantiated but only used as based class.
·   But another class can inherit from an abstract class and can create their instances
·   we can implement methods, fields, and properties in the abstract class that can be used by the child class
·   Abstract class can't be static.
·   Abstract class is used for inheritance.
·   Abstract class can't be sealed.
·   Abstract or virtual members can't be private, as we can't override it.
·   Abstract class can be inherited from an abstract class but the methods in the base class have to be declared abstract.
·   Abstract method and properties do not have any functionality. The derived class defines their full functionality.

Ex:
namespace abstract_class
{
    class Program
    {
        public abstract class clsAbstract
        {
            public abstract int sum(int a, int b);
            public abstract int subt(int a, int b);

            public void Display()
            {
                Console.WriteLine("Abstract class");
            }
        }

         public class clsDerived : clsAbstract
        {
            // Method overriding
            public override int subt(int a, int b)
            {
                return (a - b);
            }

            // Method overriding
            public override int sum(int a, int b)
            {
                return (a + b);
            }

            public void Show()
            {
                Console.WriteLine("YY class method");
            }
        }

        static void Main(string[] args)
        {
            clsDerived  obj = new clsDerived  ();

            // here you can't create instance of a abstract class it is giving error
            // clsDerived  obj1 = new clsAbstract ();
            // clsAbstract obj2 = new clsAbstract ();

            // here we have used up level casting
            clsAbstract obj3 = new clsDerived  ();
                       
            // here you don't have access to the Show method of YY
            // Because you can only access methods of a reference object only
            //obj3.Show();

            Console.WriteLine("Calling sum method through reference of base class " + obj3.sum(2,2));

            obj.Display();

            Console.WriteLine("Subtraction : "+ obj.subt(12, 10));
            Console.WriteLine("Addition : " + obj.sum(10, 10));
            Console.ReadLine();

        }
    }
}

Interface In C#

  • In C# we can define an Interface using Interface key word. Define
    //Difine an Interface
    interface MyInterface
    {
} 
  • Interfaces can be consisting of methods, properties, events, indexers or any combination of those types.
  • By default all the interface members are Public. So if we use any access modifiers it will prompt compile time error.
  • Add Interface methods have only declarations, not method implementations.
  • Class can be inherited by more than one Interface.
  • Interface can be inherited from other interface as well.
  • Interface not allows creating instances. 
    //Difine an Interface
    interface MyInterface
    {
        void MyMethods();
        void MyMethods2();
    }
    class clsMyClass : MyInterface
{
    //Can’t create Privet member
        public void MyMethods()
        {
            //Method Implementation
            Console.WriteLine("Implement Method MyMethods()");
        }

        public void MyMethods2()
        {
            //Method Implementation
            Console.WriteLine("Implement Method MyMethods2()");
        }

        public static void Main()
        {
            clsMyClass oclsMyClass = new clsMyClass();
            oclsMyClass.MyMethods();
            oclsMyClass.MyMethods2();
        }
    } 
  • When inherit from an Interface need to provide the implementation for all methods. Unless a compile error will be generated.
  • If the Class or struct is unable to provide the implementation for all methods, which are in the Interface have to be marked as Abstract.
//Difine an Interface
    interface MyInterface
    {
        void MyMethods();
        void MyMethods2();
    }
    class clsMyClass : MyInterface
    {
        public void MyMethods()
        {
            //Method Implementation
            Console.WriteLine("Implement Method MyMethods()");
        }

        //No Implementation
        abstract public void MyMethods2();


        public static void Main()
        {
            clsMyClass oclsMyClass = new clsMyClass();
            oclsMyClass.MyMethods();
            oclsMyClass.MyMethods2();
        }
    }