How can objects be late bound in .NET?

Showing Answers 1 - 3 of 3 Answers

instead of using new keyword we can use create object like in this example we are creating object to write in excel sheet through our programexampleImports Excel = Microsoft.Office.Interop.ExcelPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim objApp As Object Dim objBook As Object Dim objBooks As Object Dim objSheets As Object Dim objSheet As Object Dim range As Object ' Instantiate Excel and start a new workbook. objApp = CreateObject("Excel.Application") objBooks = objApp.Workbooks objBook = objBooks.Add objSheets = objBook.Worksheets objSheet = objSheets.Item(1) range = objSheet.Range("A1") 'Set the range value. range.Value = "Hello, World!" 'Return control of Excel to the user. objApp.Visible = True objApp.UserControl = TrueEnd Sub

  Was this answer useful?  Yes

dotnetrocks

  • Jun 7th, 2006
 

Hi,Sometimes it happens that the client does not have an idea of creating an object of which class. it has to be decided at runtime. For such condition , reflection can be used to get the type information of the class. Then we can use the Activator.createinstance class in order to create the instance of the object.

  Was this answer useful?  Yes

rich

  • Jun 12th, 2006
 

Objects are generally late bound when using class factories with interfaces (or base classes). An example of late binding can be seen below. The function that generates the concrete object (at runtime) will decide which type of concrete object to instantiateIReader reader = GetFileOrDBReader();

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions