How can we Achieve Late binding in C#.Can any give one example.
Answers were Sorted based on User's Feedback
Answer / sukriya
Polymorphism is the way of achieving late binding in csharp.
class A{}
class B:A{}
class Main
{
A a=new B();
}
| Is This Answer Correct ? | 25 Yes | 6 No |
Answer / saurabh
Its using Virtual functions.
When compiler encounters virtual keyword in an function
defination, instead of binding to the function directly,
the compiler writes a bit of dispatch code that at runtime
will look at calling objects realtype and calls the
function accordingly.
EX.
class baseClass
{
protected virtual void PrintMessage()
{
Console.WriteLine("Hi From Base Class");
}
}
class derivedClass : baseClass
{
protected override void PrintMessage()
{
Console.WriteLine("Hi From Derived Class");
}
}
public static void Main()
{
baseClass b = new baseClass();
baseClass bd = new derivedClass();
b.PrintMessage(); // prints "Hi From Base Class"
bd.PrintMessage(); // prints "Hi From Derived Class"
}
Here the runtime detects the correct type of object stored
in bd i.e. derivedClass and calls dericedClass
implementation of PrintMessage().
| Is This Answer Correct ? | 20 Yes | 4 No |
Late Binding means compiler doesn't have any prior knowledge
about COM's methods and properties and it is delayed until
runtime. Actually program learns the addresses of methods
and properties at execution time only i.e. when those
methods and properties are invoked. Late bound code
typically refers client objects through generic data types
like 'object' and relies heavily on runtime to dynamically
locate method addresses. We do late binding in C# through
reflection. Reflection is a way to determine the type or
information about the classes or interfaces.
| Is This Answer Correct ? | 18 Yes | 4 No |
Answer / kishore.a
We can achieve Late binding using Dynamic polymorphism..
| Is This Answer Correct ? | 4 Yes | 3 No |
Answer / satish
We can achive late binding through operator loading and
method ovealoading.
| Is This Answer Correct ? | 4 Yes | 12 No |
Is void a class?
What is the difference between Object and class adapters?
What is equal c#?
What?s a satellite assembly?
What is the difference between protected and internal in c#?
why C++ Partial Object Oriented Programming Language and C# and Java Fully Object Oriented Language
11 Answers 3i Infotech, Alexa, Assyst, Naresh i Technologies, TCS,
Explain the difference between the debug class and trace class?
Define an array?
What is a deadlock lock?
What do you mean by default constructor?
For methods inside the interface why can’t you specify the accessibility modifier?
What do you mean by streamreader/streamwriter class in c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)