Pages
Calender
<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
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




    C# doesn't support multiple inheritances but it is been achieved using interfaces. A class in C# has the option to implement one or more interface(S). There is only one challenge when class implements multiple interfaces is that they may include methods with same name and signature as existing class members or other interfaces' members.

    Explicit interface implementation gives the ability to hide the details of an interface and it is only available by casting to the interface type. Explicit interface implementation can be used to disambiguate class members and interface members otherwise they will conflict.

    Lets take an example, If a class implements two interfaces that contain a member with the same signature, then implementing that member on the class will cause both interfaces to use that member as their implementation.

    interface IInterfaceA
     
    {
     
        void Paint();
     
    }
     
    interface IInterfaceB
     
    {
     
       void Paint();
     
    }
     
    class SampleClassA : IInterfaceA, IInterfaceB
     
    {
     
        // Both IInterfaceA.Paint and IInterfaceA.Paint call this method.
     
        public void Paint()
     
        {
     
        }
     
    }
     

    The class member IInterfaceA.Paint is only available through the IInterfaceA interface, and IInterfaceB.Paint is only available through IInterfaceB. Both method implementations are separate, and neither is available directly on the class. For example:

    SampleClass obj = new SampleClass();
    //obj.Paint();  // Compiler error.

    IInterfaceA c = (IInterfaceA)obj;
    c.Paint();  // Calls IInterfaceA.Paint on SampleClass.

    IInterfaceB s = (IInterfaceB)obj;
    s.Paint(); // Calls IInterfaceB.Paint on SampleClass.

    It is possible to implement an interface member explicitly. Create a class member that is only called through the interface, and is specific to that interface. This can be achieved by naming the class member with the name of the interface and a period. For example:

    public class SampleClass : IInterfaceA, IInterfaceB
     
    {
     
       void IInterfaceA.Paint()
     
       {
     
            System.Console.WriteLine("IInterfaceA.Paint");
     
       }
     
       void IInterfaceB.Paint()
     
       {
     
            System.Console.WriteLine("IInterfaceB.Paint");
     
       }
     
    }



    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.