SlideShare a Scribd company logo
OOP
&
VB.NET
OOP
• Object Oriented Programming
• Deals with objects that have attributes and behaviors.
• Classes
• Is an prototype to create object
• Objects
• Is an entity that has a state and exhibits behavior
• Data Encapsulation
• Process of storing all the data members and method in a single unit
called class.
• Data Abstraction
• Process of hiding the complex details of a system and providing
only the essential features.
• Inheritance
• Inherits the members that have been already created along with
the existing members.
• Polymorphism
• ability to exist is more than one form.
Benefits
• Reusability
• Using the features of inheritance members and methods in a class can be used effectively
by the objects of an inherited class.
• Flexibility to change
• If the method has been changed that will be applicable to all the classes that inherits that
class.
• Data security
• Depending upon the security and accessibility data members can be declared private or
public
Creating Classes
• Class
• Entities that share common attributes and behaviors.
Syntax to create class
Class <<classname>>
End Class
• Class members that can be either
data objects or member functions.
Syntax of a class menmber
Class <<classname>>
Public Sub <<methodname>>
End Sub
End Class
• Object
• Declare a variable of the type class referred as object.
• Accessed using a simple dot notation.
Syntax
Dim <<objectname>> as New <<classname>>
<<objectname>>.<<methodname>>
Example
Public Class Area
Public Sub Square(side as Integer)
End Sub
End Class
Dim are1 as Area
are1.Area(10)
Creating Classes
Class Library Component
• To create a class or a reusable
component that exposes functionality
that can be used in various projects.
• Two types of applications exists
• Server class application
• Defines the class with its methods and
attributes
• Consumer client application
• Implements the methods of the class using
objects
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Class Library Component
Access Modifiers
• Specifies the availability of class and its members to
other function or program.
• Restricted to provide access to a class and to the
members of the class
• Applicable to the class are also applicable to the
members.
• Public
• The member can be accessed by any object, class or method.
Example
Public sub Square()
End Sub
• Protected
• The member can be accessed only within the class and from a derived class.
Example
Protected sub Square()
End Sub
• Friend
• The member can be accessed only within same assembly that contains it.
• Any compiled code becomes assembly.
Example
Friend sub Square()
End Sub
• Protected Friend
• The member can be accessed from the same assembly that contains the member and also
from the derived class
Example
Protected Friend sub Square()
End Sub
• Private
• The member can be accessed only within the context where it has been declared.
Example
Private sub Square()
End Sub
Access Modifiers
Methods, properties & Events
• Methods
• Group of statements.
• Properties
• Attributes of an application that is used to access the
private variables.
• Events
• Notifications sent to the application to perform predefined
actions.
Methods
• Methods
Declaration
<<access modifier>> Sub <<method name>>([<<parameter list>>])
End Sub
Parameters are optional in Methods.
Any number of parameters it can have.
Example
Public Sub display()
Console.WriteLine(“Hello”)
End Sub
Dim out as Integer
Public Sub Square(ByVal r as Integer)
out=r*4
End Sub
Methods
• Funtions
• Functions returns value.
Declaration
<<access modifier>> Function <<function name>>
(<<Parameter list>>) As <<datatype>>
Return <<variablename>>
End Function
Example
Public Function Square(ByVal r as Integer) asInteger Return 4*r
End Sub
Dim out as Integer
out=Square(4)
Console.WriteLine(out)
Properties
• Value types that allow access to
underlying private variables
• Equivalent to public variables
• A class with a public variable is similar
to a class with a public property.
• Property is more secure
• The data is stored in the underlying
private variables.
Properties
• Set method
• To set the value for the variable.
• Get method
• To retrieve the value of the variable.
• Three types
• ReadWrite
• The get and set method can be used.
• ReadOnly
• Only get method can be used.
• WriteOnly
• Only set method can be used.
Properties
• Syntax
Public Property <<PropertyName>> as <<Datatype>>
Get
Return <<variablename>>
End Get
Set(ByVal Value as <<Datatype>>)
<<variablename>> = value
End Set
End Property
Properties
• ReadWrite
Example to declare a property
Public Class Employee
Private EmployeeName as String
Public Property EmpName as String
Get
Return EmployeeName
End Get
Set(ByVal Value as <<Datatype>>)
EmployeeName = value
End Set
End Property
End Class
Example to use the property
Dim ob j as new Employee
obj.EmpName=“Kala”
Console.WriteLine(obj.EmpName)
Properties
• ReadOnly
Example to declare a property
Public Class Employee
Private EmployeeName as String = “Kala”
Public ReadOnly Property EmpName as String
Get
Return EmployeeName
End Get
End Property
End Class
Example to use the property
Dim ob j as new Employee
obj.EmpName=“Kala” ‘throw an error
Console.WriteLine(obj.EmpName)
Properties
• ReadOnly
Example to declare a property
Public Class Employee
Private EmployeeName as String
Public WriteOnly Property EmpName as String
Set(ByVal Value as <<Datatype>>)
EmployeeName = value
End Set
End Property
End Class
Example to use the property
Dim ob j as new Employee
obj.EmpName=“Kala”
Console.WriteLine(obj.EmpName) ‘throw an error
Events
• Declaration
Event <<EventName>>(ByVal <<variable>> as <<datatype>>)
Example
Event UserEvent(ByVal EventNo as Integer)
• Declares a user-defined event that can be called wheneever a certain condition is met.
• Can declare inside a class or a structure.
• Acts as a message informing an application to attend to a user or a system request.
• To raise the event use
Syntax
RaiseEvent <<EventName>>
Encapsulation
• Exposing the functionality of a class through properties and
methods while hiding the actual implementation.
Example
Class Automobile
Private Color as String
Private Tires As Integer
Public Function Drive()
‘Implementation of the drive method
End Function
Public Property BodyColor() as String
Get
Return Color
End Get
Set(ByVal Value as String)
Color=Value
End Set
End Property
Public Property NumberOfTires() as Integer
Get
Return Tires
End Get
Set(ByVal Value as String)
Tires=Value
End Set
End Property
End Class
Inheritance
• Enables one class to inherit the resources of another class.
• Achieve significant code reuse.
• Objects of one class acquire the properties of objects of another class.
• Two types of class
• Super Class or Base Class
• The class that provides the resource to another class.
• Sub Class
• The Class that inherits the resource from another class.
Inheritance
• Inherits is the keyword used to inherit the class
Syntax
<<access modifiers> Class <<Subclass>>
Inherits <<SuperClass>
End Class
Example
Public Class Motor
Inherits Automobile
End Class
Public Class Car
Inherits Automobile
End Class
Inheritance
• Visual Inheritance
• Create a normal window application
• Generate the code
• To inherit ProjectAdd Inherit form
 Open
Inheritance
Inheritance
Polymorphisim
• Ability of an object to exist in multiple
forms
• Redefining the methods on the
subclass that have been inherited
from the base class
• Overriding Methods
Namespaces
• Created class are part of Namespaces.
• Provides hierarchical grouping of types such as
classes and interfaces.
• Container containing related types
Example
System.Console
System.Data
• Creating Namespaces
Syntax
Namespace <<namespacename>>
End Namespace
• Using Namespaces
• Import Keyword is used to import namespaces.
Syntax
Imports <<namespacename>>
• Classes in the .NET framework class library can be accessed using System
namespaces
Namespaces
• Rules
• Don’t specify access type for a namespace
• Public in default
• Can’t declare a Private class inside a namespace
Example
Namespace Bank
Class SBAcc
End Class
End Namespace
Namespaces
• User Defined value data types
• Structures
• Stores multiple values in the form of a record that can be of same type or of
different types.
• Enumeration
• Named constants
• Values with unique names so that the values can be identified globally.
Valued Data Types
• Creating Structures
• Declare a Structure.
• Store the information inside it.
Syntax
Structure <<structurename>>
‘Declaration of variables
End Structure
Example
Structure Employee
Public emp_fname as String
Public emp_lname as String
Public emp_age as Double
Public emp_dob as Date
End Structure
Structures
Structures
• Accessing data
• Create objects of the structure
• Using the objects the members can be accessed by the dot
notation.
Example
Dim empobj as Employee
empobj.emp_fname=“Kala”
empobj.emp_lname=“Mala”
empobj.emp_age=10
Structure Vs Classes
Class Structure
Inheritable Not inheritable
Have constructors with or without
parameters
Have constructors only with
parameters
Have reference-type variables Have value type variables
Members can be initialized within
the class declaration
Members cannot be initialized
within the Structure declaration.
Enumeration
• Creating Enumeration
• Has an underlying base datatype which must be
numeric
• Every enumeration contains
• Name
• Underlying data type (must be Integer)
• Set of data
Syntax
<<accessmodifier>> Enum <<enumname>>
As <<numeridatatype>> <<varnam>> = [value]
End Enum
Example
Public Enum shapes
Square
rectangle
Circle
End Enum
• Assigning Values
• Assigning values to the variable is possible
Example
Public Enum shapes
Square =5
rectangle=10
Circle=15
End Enum
Public Enum shapes
Square
rectangle=10
Circle
End Enum
Enumeration
• Using Enumeration
• Create an object
• Access using dot notification
Example
Public Enum shapes
Square =5
rectangle=10
Circle=15
End Enum
Dim num as Integer
Public Function GetShapes() As shapes
Dim sha as shapes
Select Case num
case Is =5 : Return(sha.Square)
case Is =10 : Return(sha.rectangle)
case Is =15 : Return(sha.circle)
End Select
End Function
Enumeration
Referenced Data types
• Stores a pointer to another memory
location that contains data.
• Two kinds exist
• Arrays
• Classes
• Arrays
• Store multiple values of same data type using a single
name
• Values are accessed using indexes.
• Index starts from zero
• Types of Array
• Single-dimensional array
• Multi-dimensional array
• Array of array or jagged array
• Dynamic array
Single dimensional Array
• Provide name, size and data type
• Declared using Dim command.
Syntax
Dim <<arrayname>>(<<maxsize>>) as <<datatype>>
Example
Dim arr(15) as Integer
• Indexes starts from 0
• arr can store 16 values of Integer data types
Single dimensional Array
• Initializing the array
• Locate the array element using its indexes.
Example
arr(0)=1
arr(1)=10
arr(2)=20
Dim score(3 to 5 ) as Integer
• Indexes number has been explicitly
declared
• Accessing Array elements
• Done by indexes
Example
if arr(0)>0 then
Console.WriteLine(“Present”)
End if
Multi Dimensional Array
• An array having a rank more than one is called as
multi-dimensional array
• Same as table having n number of columns.
• Each column represents the entity.
• Each row represents the attribute
• Two-dimensional is the simplest form
• Has rows and columns
Multi Dimensional Array
• Creating a multi-dimensional array
• Specify the number of rows and columns
Example
Dim arr(4,5) as Integer
• Initialization
• Done by indexes
• Needs both indexes to locate
Example
arr(1,3) =20
• Accessing Elements
• Same as initialization
Example
if arr(1,3)>0 then
Console.WriteLine(“Present”)
End if
Jagged Array
• Containing another array as one of its
fields is called as jagged array
• Multi-dimensional array with irregular
dimensions
• Has arrays as its elements
• Each row of a jagged array can be
processed as an independent array
Jagged Array
• Declaration
• Multiple sets of paranthesis
Example
to declare arr(),arr1(a,b),arr2(c,d,e)
Dim arr()() As String=(New String() {“arr1”},
New String(){“a”,”b”}, New String(){“c”,”d”,”e”}}
• Initialization
• Specify the location using the indexes
Example
arr(2,2)=34
Dynamic Arrays
• At the time of creation the number of
elements are not known the size of the
array can be specified later
• This is called as Dynamic array
• Declare the array without specifying the
size
Example
Dim arr() As Integer
• As the size of the array is known declare
the array size using ReDim command
Example
Dim arr(x) As Integer

More Related Content

PPTX
Is2215 lecture2 student(2)
PPTX
PPTX
Object oriented programming
PDF
PPT
Chapter 12
DOCX
Object oriented basics
PPT
Classes and objects object oriented programming
Is2215 lecture2 student(2)
Object oriented programming
Chapter 12
Object oriented basics
Classes and objects object oriented programming

Similar to VB.net&OOP.pptx (20)

PPTX
Application package
PPTX
Concept of Object-Oriented in C++
PPT
VB.net
PPT
Object Oriented Programming In .Net
DOC
C# by Zaheer Abbas Aghani
DOC
C# by Zaheer Abbas Aghani
PPTX
Visual Basic User Interface -IV
PPTX
PPTX
Objects and classes in Visual Basic
PDF
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
PDF
Abap object-oriented-programming-tutorials
PPT
Class and object in C++
PPT
Introduction to VB.Net By William Lacktano.ppt
DOCX
Question and answer Programming
PPTX
basic concepts of object oriented programming
PPTX
OOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTS
DOCX
Object oriented Programming ____ABAP.docx
PPTX
oopusingc.pptx
PPTX
SAD05 - Encapsulation
Application package
Concept of Object-Oriented in C++
VB.net
Object Oriented Programming In .Net
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
Visual Basic User Interface -IV
Objects and classes in Visual Basic
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Abap object-oriented-programming-tutorials
Class and object in C++
Introduction to VB.Net By William Lacktano.ppt
Question and answer Programming
basic concepts of object oriented programming
OOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTS
Object oriented Programming ____ABAP.docx
oopusingc.pptx
SAD05 - Encapsulation
Ad

More from BharathiLakshmiAAssi (20)

PPT
.Net IDE Components and Applications
PPT
.Net Controlling Program Flow Statements
PPTX
Fundamentals of .Net Programming concepts
PPTX
VB.netIDE.pptx
PPT
VB.Net-Introduction.ppt
PPT
File Allocation Methods.ppt
PPTX
Demand Paging.pptx
PPTX
Virtual Memory.pptx
PPTX
Knowing about Computer SS.pptx
PPSX
Parallel Computing--Webminar.ppsx
PPSX
PPSX
Iterative Algorithms.ppsx
PPSX
Intensity Transformation.ppsx
PPSX
MAtrix Multiplication Parallel.ppsx
PPSX
Web Designing.ppsx
PPSX
Graphics Designing-Intro.ppsx
PPSX
Intensity Transformation & Spatial Filtering.ppsx
PPSX
DIP Slide Share.ppsx
PPSX
Class Timetable.ppsx
PPSX
.Net IDE Components and Applications
.Net Controlling Program Flow Statements
Fundamentals of .Net Programming concepts
VB.netIDE.pptx
VB.Net-Introduction.ppt
File Allocation Methods.ppt
Demand Paging.pptx
Virtual Memory.pptx
Knowing about Computer SS.pptx
Parallel Computing--Webminar.ppsx
Iterative Algorithms.ppsx
Intensity Transformation.ppsx
MAtrix Multiplication Parallel.ppsx
Web Designing.ppsx
Graphics Designing-Intro.ppsx
Intensity Transformation & Spatial Filtering.ppsx
DIP Slide Share.ppsx
Class Timetable.ppsx
Ad

Recently uploaded (20)

PPTX
Self management and self evaluation presentation
PPTX
Primary and secondary sources, and history
PDF
Presentation1 [Autosaved].pdf diagnosiss
PPTX
An Unlikely Response 08 10 2025.pptx
PPTX
The spiral of silence is a theory in communication and political science that...
PPTX
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
lesson6-211001025531lesson plan ppt.pptx
PDF
Nykaa-Strategy-Case-Fixing-Retention-UX-and-D2C-Engagement (1).pdf
PPT
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
water for all cao bang - a charity project
PPTX
Project and change Managment: short video sequences for IBA
PPTX
Introduction-to-Food-Packaging-and-packaging -materials.pptx
PDF
Parts of Speech Prepositions Presentation in Colorful Cute Style_20250724_230...
PDF
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
PPTX
ART-APP-REPORT-FINctrwxsg f fuy L-na.pptx
PPTX
2025-08-10 Joseph 02 (shared slides).pptx
PPTX
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
PPTX
English-9-Q1-3-.pptxjkshbxnnxgchchxgxhxhx
PPT
First Aid Training Presentation Slides.ppt
PPTX
Impressionism_PostImpressionism_Presentation.pptx
Self management and self evaluation presentation
Primary and secondary sources, and history
Presentation1 [Autosaved].pdf diagnosiss
An Unlikely Response 08 10 2025.pptx
The spiral of silence is a theory in communication and political science that...
The Effect of Human Resource Management Practice on Organizational Performanc...
lesson6-211001025531lesson plan ppt.pptx
Nykaa-Strategy-Case-Fixing-Retention-UX-and-D2C-Engagement (1).pdf
The Effect of Human Resource Management Practice on Organizational Performanc...
water for all cao bang - a charity project
Project and change Managment: short video sequences for IBA
Introduction-to-Food-Packaging-and-packaging -materials.pptx
Parts of Speech Prepositions Presentation in Colorful Cute Style_20250724_230...
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
ART-APP-REPORT-FINctrwxsg f fuy L-na.pptx
2025-08-10 Joseph 02 (shared slides).pptx
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
English-9-Q1-3-.pptxjkshbxnnxgchchxgxhxhx
First Aid Training Presentation Slides.ppt
Impressionism_PostImpressionism_Presentation.pptx

VB.net&OOP.pptx

  • 2. OOP • Object Oriented Programming • Deals with objects that have attributes and behaviors. • Classes • Is an prototype to create object • Objects • Is an entity that has a state and exhibits behavior • Data Encapsulation • Process of storing all the data members and method in a single unit called class. • Data Abstraction • Process of hiding the complex details of a system and providing only the essential features. • Inheritance • Inherits the members that have been already created along with the existing members. • Polymorphism • ability to exist is more than one form.
  • 3. Benefits • Reusability • Using the features of inheritance members and methods in a class can be used effectively by the objects of an inherited class. • Flexibility to change • If the method has been changed that will be applicable to all the classes that inherits that class. • Data security • Depending upon the security and accessibility data members can be declared private or public
  • 4. Creating Classes • Class • Entities that share common attributes and behaviors. Syntax to create class Class <<classname>> End Class • Class members that can be either data objects or member functions. Syntax of a class menmber Class <<classname>> Public Sub <<methodname>> End Sub End Class
  • 5. • Object • Declare a variable of the type class referred as object. • Accessed using a simple dot notation. Syntax Dim <<objectname>> as New <<classname>> <<objectname>>.<<methodname>> Example Public Class Area Public Sub Square(side as Integer) End Sub End Class Dim are1 as Area are1.Area(10) Creating Classes
  • 6. Class Library Component • To create a class or a reusable component that exposes functionality that can be used in various projects. • Two types of applications exists • Server class application • Defines the class with its methods and attributes • Consumer client application • Implements the methods of the class using objects
  • 25. Access Modifiers • Specifies the availability of class and its members to other function or program. • Restricted to provide access to a class and to the members of the class • Applicable to the class are also applicable to the members.
  • 26. • Public • The member can be accessed by any object, class or method. Example Public sub Square() End Sub • Protected • The member can be accessed only within the class and from a derived class. Example Protected sub Square() End Sub • Friend • The member can be accessed only within same assembly that contains it. • Any compiled code becomes assembly. Example Friend sub Square() End Sub • Protected Friend • The member can be accessed from the same assembly that contains the member and also from the derived class Example Protected Friend sub Square() End Sub • Private • The member can be accessed only within the context where it has been declared. Example Private sub Square() End Sub Access Modifiers
  • 27. Methods, properties & Events • Methods • Group of statements. • Properties • Attributes of an application that is used to access the private variables. • Events • Notifications sent to the application to perform predefined actions.
  • 28. Methods • Methods Declaration <<access modifier>> Sub <<method name>>([<<parameter list>>]) End Sub Parameters are optional in Methods. Any number of parameters it can have. Example Public Sub display() Console.WriteLine(“Hello”) End Sub Dim out as Integer Public Sub Square(ByVal r as Integer) out=r*4 End Sub
  • 29. Methods • Funtions • Functions returns value. Declaration <<access modifier>> Function <<function name>> (<<Parameter list>>) As <<datatype>> Return <<variablename>> End Function Example Public Function Square(ByVal r as Integer) asInteger Return 4*r End Sub Dim out as Integer out=Square(4) Console.WriteLine(out)
  • 30. Properties • Value types that allow access to underlying private variables • Equivalent to public variables • A class with a public variable is similar to a class with a public property. • Property is more secure • The data is stored in the underlying private variables.
  • 31. Properties • Set method • To set the value for the variable. • Get method • To retrieve the value of the variable. • Three types • ReadWrite • The get and set method can be used. • ReadOnly • Only get method can be used. • WriteOnly • Only set method can be used.
  • 32. Properties • Syntax Public Property <<PropertyName>> as <<Datatype>> Get Return <<variablename>> End Get Set(ByVal Value as <<Datatype>>) <<variablename>> = value End Set End Property
  • 33. Properties • ReadWrite Example to declare a property Public Class Employee Private EmployeeName as String Public Property EmpName as String Get Return EmployeeName End Get Set(ByVal Value as <<Datatype>>) EmployeeName = value End Set End Property End Class Example to use the property Dim ob j as new Employee obj.EmpName=“Kala” Console.WriteLine(obj.EmpName)
  • 34. Properties • ReadOnly Example to declare a property Public Class Employee Private EmployeeName as String = “Kala” Public ReadOnly Property EmpName as String Get Return EmployeeName End Get End Property End Class Example to use the property Dim ob j as new Employee obj.EmpName=“Kala” ‘throw an error Console.WriteLine(obj.EmpName)
  • 35. Properties • ReadOnly Example to declare a property Public Class Employee Private EmployeeName as String Public WriteOnly Property EmpName as String Set(ByVal Value as <<Datatype>>) EmployeeName = value End Set End Property End Class Example to use the property Dim ob j as new Employee obj.EmpName=“Kala” Console.WriteLine(obj.EmpName) ‘throw an error
  • 36. Events • Declaration Event <<EventName>>(ByVal <<variable>> as <<datatype>>) Example Event UserEvent(ByVal EventNo as Integer) • Declares a user-defined event that can be called wheneever a certain condition is met. • Can declare inside a class or a structure. • Acts as a message informing an application to attend to a user or a system request. • To raise the event use Syntax RaiseEvent <<EventName>>
  • 37. Encapsulation • Exposing the functionality of a class through properties and methods while hiding the actual implementation. Example Class Automobile Private Color as String Private Tires As Integer Public Function Drive() ‘Implementation of the drive method End Function Public Property BodyColor() as String Get Return Color End Get Set(ByVal Value as String) Color=Value End Set End Property Public Property NumberOfTires() as Integer Get Return Tires End Get Set(ByVal Value as String) Tires=Value End Set End Property End Class
  • 38. Inheritance • Enables one class to inherit the resources of another class. • Achieve significant code reuse. • Objects of one class acquire the properties of objects of another class. • Two types of class • Super Class or Base Class • The class that provides the resource to another class. • Sub Class • The Class that inherits the resource from another class.
  • 39. Inheritance • Inherits is the keyword used to inherit the class Syntax <<access modifiers> Class <<Subclass>> Inherits <<SuperClass> End Class Example Public Class Motor Inherits Automobile End Class Public Class Car Inherits Automobile End Class
  • 40. Inheritance • Visual Inheritance • Create a normal window application • Generate the code • To inherit ProjectAdd Inherit form  Open
  • 43. Polymorphisim • Ability of an object to exist in multiple forms • Redefining the methods on the subclass that have been inherited from the base class • Overriding Methods
  • 44. Namespaces • Created class are part of Namespaces. • Provides hierarchical grouping of types such as classes and interfaces. • Container containing related types Example System.Console System.Data
  • 45. • Creating Namespaces Syntax Namespace <<namespacename>> End Namespace • Using Namespaces • Import Keyword is used to import namespaces. Syntax Imports <<namespacename>> • Classes in the .NET framework class library can be accessed using System namespaces Namespaces
  • 46. • Rules • Don’t specify access type for a namespace • Public in default • Can’t declare a Private class inside a namespace Example Namespace Bank Class SBAcc End Class End Namespace Namespaces
  • 47. • User Defined value data types • Structures • Stores multiple values in the form of a record that can be of same type or of different types. • Enumeration • Named constants • Values with unique names so that the values can be identified globally. Valued Data Types
  • 48. • Creating Structures • Declare a Structure. • Store the information inside it. Syntax Structure <<structurename>> ‘Declaration of variables End Structure Example Structure Employee Public emp_fname as String Public emp_lname as String Public emp_age as Double Public emp_dob as Date End Structure Structures
  • 49. Structures • Accessing data • Create objects of the structure • Using the objects the members can be accessed by the dot notation. Example Dim empobj as Employee empobj.emp_fname=“Kala” empobj.emp_lname=“Mala” empobj.emp_age=10
  • 50. Structure Vs Classes Class Structure Inheritable Not inheritable Have constructors with or without parameters Have constructors only with parameters Have reference-type variables Have value type variables Members can be initialized within the class declaration Members cannot be initialized within the Structure declaration.
  • 51. Enumeration • Creating Enumeration • Has an underlying base datatype which must be numeric • Every enumeration contains • Name • Underlying data type (must be Integer) • Set of data Syntax <<accessmodifier>> Enum <<enumname>> As <<numeridatatype>> <<varnam>> = [value] End Enum Example Public Enum shapes Square rectangle Circle End Enum
  • 52. • Assigning Values • Assigning values to the variable is possible Example Public Enum shapes Square =5 rectangle=10 Circle=15 End Enum Public Enum shapes Square rectangle=10 Circle End Enum Enumeration
  • 53. • Using Enumeration • Create an object • Access using dot notification Example Public Enum shapes Square =5 rectangle=10 Circle=15 End Enum Dim num as Integer Public Function GetShapes() As shapes Dim sha as shapes Select Case num case Is =5 : Return(sha.Square) case Is =10 : Return(sha.rectangle) case Is =15 : Return(sha.circle) End Select End Function Enumeration
  • 54. Referenced Data types • Stores a pointer to another memory location that contains data. • Two kinds exist • Arrays • Classes • Arrays • Store multiple values of same data type using a single name • Values are accessed using indexes. • Index starts from zero • Types of Array • Single-dimensional array • Multi-dimensional array • Array of array or jagged array • Dynamic array
  • 55. Single dimensional Array • Provide name, size and data type • Declared using Dim command. Syntax Dim <<arrayname>>(<<maxsize>>) as <<datatype>> Example Dim arr(15) as Integer • Indexes starts from 0 • arr can store 16 values of Integer data types
  • 56. Single dimensional Array • Initializing the array • Locate the array element using its indexes. Example arr(0)=1 arr(1)=10 arr(2)=20 Dim score(3 to 5 ) as Integer • Indexes number has been explicitly declared • Accessing Array elements • Done by indexes Example if arr(0)>0 then Console.WriteLine(“Present”) End if
  • 57. Multi Dimensional Array • An array having a rank more than one is called as multi-dimensional array • Same as table having n number of columns. • Each column represents the entity. • Each row represents the attribute • Two-dimensional is the simplest form • Has rows and columns
  • 58. Multi Dimensional Array • Creating a multi-dimensional array • Specify the number of rows and columns Example Dim arr(4,5) as Integer • Initialization • Done by indexes • Needs both indexes to locate Example arr(1,3) =20 • Accessing Elements • Same as initialization Example if arr(1,3)>0 then Console.WriteLine(“Present”) End if
  • 59. Jagged Array • Containing another array as one of its fields is called as jagged array • Multi-dimensional array with irregular dimensions • Has arrays as its elements • Each row of a jagged array can be processed as an independent array
  • 60. Jagged Array • Declaration • Multiple sets of paranthesis Example to declare arr(),arr1(a,b),arr2(c,d,e) Dim arr()() As String=(New String() {“arr1”}, New String(){“a”,”b”}, New String(){“c”,”d”,”e”}} • Initialization • Specify the location using the indexes Example arr(2,2)=34
  • 61. Dynamic Arrays • At the time of creation the number of elements are not known the size of the array can be specified later • This is called as Dynamic array • Declare the array without specifying the size Example Dim arr() As Integer • As the size of the array is known declare the array size using ReDim command Example Dim arr(x) As Integer