Hi there,

I see a sample code that an object is instantiated within the
class definition block. But when I test the folllowing, I got
error "Process is terminated due to StackOverflowException."?

Imports System
Module xx
	Sub Main()
		Dim a As New c()
	End Sub
End Module

Public Class c
	Dim b As New c()
End Class

Thanks

A Huang

Yes, because that is an infinity loop.
You create a new class "c" and each time you create a new c you create again a new c...

Dim testStudent As New Student() 'Class Student does NOT have a "New" initializer so. Thats used for initialise a class and call a function from that class
testStudent.PerformOperations() 'Call function from that class (which actually just fills its properties)
Class Student 
Public Sub PerformOperations() 
Dim st1 As New Student()    ' creating new instance of Student to get access of its properties
st1.name = "Einstein"       ' setting the values of fields 
...
End Sub
End Class

tbh i dont know what they created a new class of its own in that function. would be easier to fill its properties just like
Me.name = "Einstein"

Edited 6 Years Ago by GeekByChoiCe: n/a

This article has been dead for over six months. Start a new discussion instead.