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


A Huang

8 Years
Discussion Span
Last Post by GeekByChoiCe

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 by GeekByChoiCe: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.