Return New#Second Post - Rephrasing question #Unable to delete previous post

  • Thread starter Thread starter sougata12
  • Start date Start date
S

sougata12

Guest
Module Module1

Public Class car
Public Property make As String
End Class

Sub main()
returnClass().make = "Ford"
Console.WriteLine("Value returned: {0}", returnClass().make)
Console.ReadLine()
End Sub

Public Function returnClass() As car
Return New car
End Function

End Module

My Question:
What does the statement "Return New Car" return from the function returnClass? Does it automatically create a new instance of the class named CAR and returns that? Or does it return a null value? OR does it return something else?

Thought process behind my code: Why is it written in the way you see?
I was under the impression that the statement "Return New Car" is returning a new instance of the CAR class. The code is written to test that understanding. The idea was to capture the memory address (or reference) of whatever is being returned from the function returnClass . Then assign a value to the Make property and print that value. However nothing is getting printed as seen below. This means either my understanding that some reference is being passed from the function is wrong or the way I am capturing that reference in the main program is wrong. Whatever be it, I need your help to understand what is being returned by the statement "Return New Car".

1485565.png

What is the source of the statement "Return New Car"?
I came across an example with the statement "Return New Car" in the following MSDN documentation. SHARED (MSDN Documentation)

The purpose of the example mentioned in that documentation is completely different but since I found the statement "Return New Car" a new way of using the RETURN statement (in the sense that it is not returning the name of an instance of CAR type) I just wanted to understand it better.

Looking forward to any sort of help from you experts,

Thanks,

Sougata




Sougata Ghosh

Continue reading...
 
Back
Top