objects and classes in vb.net
This is a really great article for beginners who want to learn about classes and objects in vb.net (any version)
An object is an instance of a CLASS
E.G: car1 and car2 in the following code.>>
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
‘car1 is an object and it is an instance of the Car CLASS.>>
Dim car1 As New Car
‘car2 is an object and it is an instance of the Car CLASS.>>
Dim car2 As New Car
End Sub
End Class
Public Class Car
‘No code added yet. 🙂
End Class
A CLASS can contain PROPERTIES ( it doesn’t have to ), a CLASS can contain one or more SUBs ( it doesn’t have to ) a CLASS can also contain FUNCTIONs ( it doesn’t have to ) a CLASS may also contain one or more STRUCTUREs ( it doesn’t have to ) and a CLASS may also contain one or more ENUMs ( again it doesn’t have to ).
At the end of the day the programmer decides what He or She wants to write in code within a CLASS. 🙂
Do not get overly concerned about not knowing all of this yet, take it easy,
learn about things in small stages until you remember it.
An object such as a Car will have a property associated with it such as its color.
Define the property in the CLASS so you can use it in the object. like this.>>
When you type the word PROPERTY within a class hit the TAB key twice and most of it appears. 🙂
Then just ensure you edit it correctly.
The PRIVATE value is usually returned in the GET section. The PRIVATE value is set in the SET section.
If you want to know why, just ask.
Here is an example showing car1 as a Car having the color red, car2 has a color property of blue. >>
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim car1 As New Car
car1.Color = Color.Red
Dim car2 As New Car
car2.Color = Color.Blue
End Sub
End Class
Public Class Car
Private clr As Color
Public Property Color() As Color
Get
Return Me.clr
End Get
Set(ByVal value As Color)
Me.clr = value
End Set
End Property
End Class
Question : “Hi there can i say object as a Noun means like i(saurabh) is an instance of humans ”
Answer : Hi,
Yes, you are an instance of a human. 🙂 I am another instance. 🙂
So a CLASS is a template for each person so that each person can have different property values set.
Well thanks a ton to john anthony oliver of msdn for helping me out
and if you want to see my whole topic see here
>>>
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/c04d74ba-6d53-4757-8e9e-0619daa87011