Pages
Calender
<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
Blogroll
    Ajander Singh , Created On 2. May 2010, 18:59

    About The Book
    Get expert guidance to exploit CLR capabilities and the Microsoft .NET Framework 4.0.

    Dig deep and master the intricacies of the common language runtime (CLR) and the .NET Framework 4.0. Written by a highly regarded programming expert and consultant to the Microsoft .NET team, this guide is ideal for developers building any kind of application—including Microsoft ASP.NET, Windows® Forms, Microsoft SQL Server®, Web services, and console applications. You’ll get hands-on instruction and extensive C# code samples to help you tackle the tough topics and develop high-performance applications.

    CLR VIA C# Jeffrey Richter

    About the Author: Jeffrey Richter

    Dig deep and master the intricacies of the common language runtime (CLR) and the .NET Framework 4.0. Written by a highly regarded programming expert and consultant to the Microsoft® .NET team, this guide is ideal for developers building any kind of application-including Microsoft® ASP.NET, Windows® Forms, Microsoft® SQL Server®, Web services, and console applications. You’ll get hands-on instruction and extensive C# code samples to help you tackle the tough topics and develop high-performance applications. It is October 2009 as I write this text, making it 10 years now that I’ve worked with the .NET Framework and C#. Over the 10 years, I have built all kinds of applications and, as a consultant to Microsoft, have contributed quite a bit to the .NET Framework itself. As a partner in my own company, Wintellect (http://Wintellect.com), I have worked with numerous customers to help them design software, debug software, performance-tune software, and solve issues they have with the .NET Framework. All these experiences have really helped me learn the spots that people have trouble with when trying to be productive with the .NET Framework. I have tried to sprinkle knowledge from these experiences through all the topics presented in this book.

    Information gathered from Microsoft Site or log on to http://www.microsoft.com/learning/en/us/books.aspx?ID=13874&Locale=en-us

    Publisher: Microsoft Press | ISBN: 0735627045 | Feb 2010 | PDF | 896 pages | 18.6 Mb

    Download: Here



    ajander singh , Created On 1. April 2010, 19:04

    An interface contains only the signatures of methods,  events, indexers or properties. When a class or struct implements the interface then that class/struct must implement the members of the interface that are specified in the interface definition.

    interface IEquatable<T> 
    {
         bool Equals(T obj); 
    }

    An interface cannot contain fields and members are automatically public in interface as well and an interface can inherit from one or more base interfaces. When a base type list contains a base class and interfaces, the base class must come first in the list.

    A class that implements an interface can explicitly implement members of that interface. An explicitly implemented member cannot be accessed through a class instance, but only through an instance of the interface.

    Interfaces can inherit other interfaces. It is possible for a class to inherit an interface multiple times, through base classes or interfaces it inherits. In this case, the class can only implement the interface one time, if it is declared as part of the new class. If the inherited interface is not declared as part of the new class, its implementation is provided by the base class that declared it. It is possible for a base class to implement interface members using virtual members; in that case, the class inheriting the interface can change the interface behavior by overriding the virtual members.

    it was necessary to incorporate some other method so that the class can inherit the behavior of more than one class, avoiding the problem of name ambiguity that is found in C++. With name ambiguity, the object of a class does not know which method to call if the two base classes of that class object contain the same named method.


    Interfaces Overview

    An interface has the following properties:

    •       An interface is like an abstract base class: any non-abstract type inheriting the interface must implement all its members.
    •       An interface cannot be instantiated directly.
    •       Interfaces can contain events, indexers, methods and properties.
    •       Interfaces contain no implementation of methods.
    •       Classes and structs can inherit from more than one interface.
    •       An interface can itself inherit from multiple interfaces.



    As developers knows that many arithmetic operations on primitives types could result in an overflow:

    Byte b=100;
    b=(Byte) (b+200);       //b now contains 44 (2c in hex)

    In some cases silent overflow can give undesirable results, and if not detected causes the application to behave in strange and unusual ways. Many languages handles overflows in different ways. Like C and C++ allows overflow and is not considered as an error and allow the value to wrap; allows to application continues running. Microsoft visual basic always considers overflows to be an errors and throws an exception when it detects.

    The common language runtime (CLR) offers IL (Intermediate language) instructions that allow the compiler to choose the desired behavior. as you know the C# compiler generated IL has an add instruction as it the default behavior for C# to generate silent overflow. C# compiler use the /checked+ compiler switch to control the overflow, which tell the C# compiler to uses the safe version of the add with overflow check , add.ovf which will prevent this kind of silent overflow and throw OverflowException if overflow occur.

    C# allows the programmer to decide how overflow should be handled. as you know, By default overflow checking is turned off. this means that the compiler generates IL code by using the versions of the add, subtract, multiply, and conversion instructions that don't include overflow checking. as a result, the code runs faster but developers must be assured that overflows won't occur or that their code is designed to anticipate these overflows.

    If overflow occur, the CLR throws an OverflowException. You should design your application's code to handle this exception. Rather than have overflow checking turned off on or off globally, C# allows this flexibility by offering checked and unchecked operators. Simply checked operator tells the C# compiler to use the safe IL instruction for this operation , and the unchecked use the normal IL instructions (which is the normal behavior in C#).

    Here is an example that use checked operator:

    Byte b=100;
    b=checked((Byte)(b+200));                  //OverflowException is thrown

    If the Byte cast outside the checked operator, the exception wouldn't be occurred.

    b=(Byte)checked((b+200));                 //no OverflowException

    In addition to the checked and unchecked operators, C# also offers checked and unchecked statements. the statements cause all expressions within a block to be checked or unchecked:

    checked{
     Byte b=100;
     b=(Byte((b=200);
    }

    Now, try to turn on the compiler's switch /checked+ switch for debug build. Your application will run slowly because the system will be checking for overflow on any code that you didn't explicitly mark as checked and unchecked. If an exception occurs, you will be able to easily detect and be able to fix the bug in you application.