I am studying VB.NET and I have a question about copying Class instance.
For example, I have
Public Class frmMain_CLT
Public Shared GEN_SETTING As MY_OBJ
Public Sub frmMain_CLT_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Test_GM As MY_OBJ ' I would like to copy GEN_SETTING to Test_GM
End Sub
End Class
I would like to copy GEN_SETTING to Test_GM
I know that I can use "Test_GM = GEN_SETTING". However, Test_GM will reference GEN_SETTING. Therefore, Data, where is in the GEN_SETTING will change when I modify Data in the Test_GM.
I would like to make Copy of GEN_SETTING to Test_GM , which is "NOT" referencing original Copy.
But i am not sure how to do it. I was thinking about DirectCast to copy instance but I am getting Error..
Update
I just created Clone method in the MY_OBJ class
for example,
Public Function ShallowCopy() As MY_OBJ
Return DirectCast(Me.MemberwiseClone(), MY_OBJ)
End Function
However, I am not really sure if it is the best way to copy class instance