Classes and Data types in VB NET Lecture

Classes and Data types in VB. NET Lecture 2

Objectives Understand data types n Understand the role of classes n Understand objects n Learn VB. NET class Syntax n

Data type n A definition of a set of data that specifies the possible range of values of the set, the operations that can be performed on the values, and the way in which the values are stored in memory.

Data type n In programming languages a data type defines a set of values and the allowable operations on those values (http: //en. wikipedia. org/wiki/Data_type)

Data types n Integer ¨ Operations: n String ¨ Operations: n +, - , *, / Substring(), Trim() Date. Time ¨ Operations: Add. Days(), Add. Years()

What is a class? One of the primary uses of OOP is to develop user-defined data types. n Class is a user defined Data type. n

What is an Object? Object is an instance of a class n In other words you create an object by declaring a variable of a particular class type. n

What is an Object? n. A type is just a. NET class. (http: //visualbasic. about. com/od/usingvbnet/a/datatypes. htm)

Classes in VB. NET Public Class Boat Private _width As Integer Private _length As Integer 'More stuff goes here' End Class

Constructors Public Sub New() _width = 10 _length = 110 End Sub Public Sub New(w As Integer, l As _Integer) _width = w _length = l End Sub

Properties Public Class Boat Private _width As Integer Public Property Width() As Integer Get Return _width End Get Set(By. Value As Integer) _width = Value End Set End Property End Class

Subs and Functions Public Sub Add. Person(p as Person) … End Sub Public Function Get. Current. Load() As Integer … End Function

The End
- Slides: 13