Diff. B/w Imports & Inherits?

  • Thread starter Thread starter Arpan
  • Start date Start date
A

Arpan

What's the difference between "Imports" & "Inherits"? For e.g. both the
codes below work without any errors:

Imports System
Imports System.Data
Imports System.Web.UI

Namespace Constructors
Public Class Constr : Inherits Page
Public Sub New()
Response.Write("Constructor1")
End Sub
End Class
End Namespace

----------

Imports System
Imports System.Data

Namespace Constructors
Public Class Constr : Inherits System.Web.UI.Page
Public Sub New()
Response.Write("Constructor1")
End Sub
End Class
End Namespace

In the first code snippet, I am importing "System.Web.UI" & then
inheriting the "Page" class where as in the second code snippet, I am
just inheriting "System.Web.UI.Page". So what's the difference between
importing & inheriting?

Thanks,

Arpan
 
Imports just allows you to not have to type out the namespace that
contains the class every single time. So, by declaring Imports
System.Web.UI, and then doing Page, it knows which class you want,
without using the Imports statement, you would have to type out
System.Web.UI.Page everytime.

the "Inherits" keyword is completely unrelated. This has to do with
Object Oriented Programming and one of its many features. Search for
OOP on wikipedia.org, as this topic as a whole is out of the scope of
this thread.

Hope this helps!

Sean
 
Back
Top