Results 1 to 6 of 6

Thread: Late Binding in C#

  1. #1
    Join Date
    May 2008
    Posts
    2,012

    Late Binding in C#

    Hi, I am student of BSC.I.T. In last lecture we had got the lesson of late binding in c#. But I don't able to get it. Can anyone give me explanation about it in simple words.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Late Binding in C#

    Hi, There are two types of Polymorphism. One is Static polymorphism and Dynamic polymorphism. Static polymorphism is also known as Early Binding and Dynamic polymorphism is also known as Late Binding.

    Polymorphism is achieved as follow with the help of c#:

    Code:
    class One
    {
    }
    class Two:One
    {
    }
    class Main
    {
    One oo=new Two();
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Late Binding in C#

    Hi, you can make use of the Late Binding in C# with the help of Virtual function. When compiler finds virtual keyword in an function defination, while compiling, instead of binding to the function directly, it wait for the runtime to execute further. You will get it by taking look at following:
    Code:
    class base
    {
    
      protected virtual void PrintMessage()
       {
         Console.WriteLine("You are in Base Class");
       }
    }
    
    class derived : base
    {
       protected override void PrintMessage()
       {
         Console.WriteLine("You are in Derived Class");
       }
    
    }
    
    public static void Main()
    {
      base b = new base();
      base d = new derived();
    
      b.PrintMessage(); /*This will print:You are in Base Class*/
      d.PrintMessage(); /* This will print:You are in Derived Class*/
    }

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Late Binding in C#

    Hi, I don't know how to achieve the late binding in C#, but while searching on internet I have got something which will create a console application to test DLLs with reflection and also it uses late binding to achieve this. Just check whether it is helpful to you or not.

    Code:
    using System;
    using System.Reflection;
    using System.IO;
    
    static void Main()
    {
    string[] filenames = Directory.GetFiles(Environment.CurrentDirectory,CommonP2P.strSearchDLL);
    
    foreach (string filename in filenames)
    {
    Console.WriteLine("Load Protocol: {0}", filename);
    Assembly a = Assembly.LoadFrom(filename);
    Type[] types = a.GetTypes();
    foreach (Type typ in types)
    {
    object obj = Activator.CreateInstance(typ);
    MethodInfo mi = typ.GetMethod("MyMsg");
    mi.Invoke(0, null);
    }
    }
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: Late Binding in C#

    Hi, Late Binding means compiler doesn't have any prior knowledge about the methods and properties of the class and it is delayed until runtime. So, basically programs don't know the addresses of methods and properties at compile time, it gets all those stuff at the time of execution, that is at the time of invocation of those particular method. Late Binding refers to only the generic data type. Most of the time late binding in C# is achieved through reflection. Reflection is a way to determine the type or information about the classes or interfaces.

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Late Binding in C#

    Hi, Basically when compiler connects the method call to the method body is called as binding. So when this binding is done at the time of compiling it is termed as early binding. And if at the time of compilation compiler don't get the method body to which the method call has to be binded, it is called as late binding. As then that method is binded at run time. Late binding is also called dynamic binding or run-time binding. This mechanism varies from language to language.

Similar Threads

  1. Modern Warfare 2 key binding
    By Coty in forum Video Games
    Replies: 4
    Last Post: 26-03-2010, 04:18 PM
  2. How to break through ip plus mac binding?
    By Langward in forum Networking & Security
    Replies: 5
    Last Post: 24-03-2010, 02:12 AM
  3. What is Data Binding?
    By Rum in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 12:15 PM
  4. early binding in a C++
    By Porfirioo in forum Software Development
    Replies: 5
    Last Post: 27-11-2009, 06:45 PM
  5. manual Binding OR ObjectDataSource
    By AmolP in forum Software Development
    Replies: 4
    Last Post: 04-02-2009, 07:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,719,792.83491 seconds with 16 queries