borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (why web user control can not run independly ?)Next Topic (DotNet application installation on windows 98) New Topic New Poll Post Reply
AndreaVB Forum : ASP.Net : how to declare inner class in vb.net
Poster Message
tri_inn
Level: Regular User
Registered: 26-08-2002
Posts: 395

icon how to declare inner class in vb.net

please tell me that how to declare inner class in vb.net and what is the advantage of inner class. when i should declare inner class.

09-07-2004 at 06:34 AM
View Profile Send Email to User Show All Posts | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: how to declare inner class in vb.net

An inner class has the advantage of organizing your code logically. An example of this is the ListViewItemCollection class in the System.Windows.Forms namespace. This class serves no purpose outside a ListView so it is declared as an inner class.

To declare one, all you have to do is create the class definition inside the implementation like this:

Public Class HumanBeing
  'code for human properties and methods

  Public Class Brain
     'code for brain here
  End Class 'brain
End Class 'human


In this imaginary example a brain can only be used in the context of a human. To create an instance of this class you would write code like the following:

Dim br As New HumanBeing.Brain


In some cases you may want the inner class to be private. This means that other classes know nothing about this inner class (private class). A common scenario I use it in is in Windows applications for forms that need to do extensive printing work. Each Form has its own different requirements and I create the inner class (normally called PrintHelper) to handle the printing process on a different thread. It receives the data to print and the process is then started on a new thread while the print form hides or unloads and normal processing can go on.

Other classes cannot create instances of this inner class and they do not know anything about them because its scope is private to the class in which it is defined.

Happy coding.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

12-07-2004 at 05:13 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : ASP.Net : how to declare inner class in vb.net
Previous Topic (why web user control can not run independly ?)Next Topic (DotNet application installation on windows 98) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder