Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 27-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
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.
Reply With Quote
  #2  
Old 27-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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();
}
Reply With Quote
  #3  
Old 27-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
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*/
}
Reply With Quote
  #4  
Old 27-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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);
}
}
}
Reply With Quote
  #5  
Old 27-11-2009
Member
 
Join Date: May 2008
Posts: 2,383
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #6  
Old 27-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 08:58 AM.