In VB.NET, Constructor always named as 'New' and is a sub procedure.
In C#, Constructor name is same as Class Name and does'nt have a return type not even void.
Constructor with no parameters is called Default Constructor and the one with parameters is called Parametrized Constructor.
Copy Constructor is used to copy data members of the existing object to new object data members.
In VB.NET, Public Sub New() 'Default Constructor End Sub public Sub New(ByVal id as integer, ByVal Name as string) Me.New() 'Calling Default Constructor first.. 'this is Parametrized Constructor.. End Sub | In C#, Public Class Account { Public Account() //Construtor name same as class name... { //Default Constructor.. } Public Account(int id, String name) : this() { //Parameterized Constructor... } } |
From the above table, it is clear that constructors can be overloaded.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.