Click here to Skip to main content
15,896,726 members
Articles / Web Development / ASP.NET

Object Oriented Programming In VB.NET

Rate me:
Please Sign up or sign in to vote.
4.19/5 (150 votes)
18 Nov 20048 min read 747K   8.6K   257  
A must read for anyone who is interested in VB.NET. This article uncovers some basic Object Oriented Programming features of Visual Basic .NET. The whole article is divided into 10 lessons. The source code for these lessons is provided with the article.
'@desc: 4 : Over Loading Functions

'LESSON 4: OVERLOADING
'----------------------------------------------------

'-----------------------------------------------------------------
'Import the System namespace (already available in .NET)
Imports System
'-----------------------------------------------------------------


'Overloading is a simple technique, to enable a single
'function name to accept parameters of different type.


'Our simple Adder class
Class Adder

    'Here, we have two Add() functions. 
    
    'This one adds two integers.
    'Convert.ToString is equivalent to good old Cstr  
      
	Overloads Public Sub Add(A as Integer, B as Integer)
		Console.Writeline ("Adding Integers: " + Convert.ToString(a + b))
	End Sub
	

    'This one adds two strings
	Overloads Public Sub Add(A as String, B as String)
		Console.Writeline ("Adding Strings: " + a + b)
	End Sub
	
	'And both have the same name. This is possible because, we used the
	'Overloads keyword, to overload them.
	
	
	'Here, we have the Main Function with in this class. When you write.
	'your main function inside the class, it should be a shared function.
	
	Shared Sub Main() 
		
		Dim AdderObj as Adder
		
		'Create the object
		AdderObj=new Adder
		
		'This will invoke first function
		AdderObj.Add(10,20)
		'This will invoke second function
		AdderObj.Add("hello"," how are you")
		
		
	End Sub
	
	
End Class



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
India India
Architect, Developer, Speaker | Wannabe GUT inventor & Data Scientist | Microsoft MVP in C#

Comments and Discussions