In VB, I have classes that look like:
Public Class Example
Public test1 As New List(of String)
Public test2 As New List(of String)
Public Sub Init()
//code logic here
End Sub
End Class
My understanding is that this Sub Init() procedure works like a main method in C#, in that everytime the Example class is used, this method is initialized automatically. Is this a correct understanding? How would this sub procedure be written in C#?
My understanding is that this Sub Init() procedure works like a main method in C#, in that everytime the Example class is used, this method is initialized automatically.
No, that's not a correct understanding of either the Init
method or the Main
method in C#, as far as I'm aware.
This is just a method named Init
, with nothing special about it. If this were a New
method, that would correspond to a C# constructor, but that's a different matter.
Your class is equivalent to:
using System.Collections.Generic;
public class Example
{
public List<string> test1 = new List<string>();
public List<string> test2 = new List<string>();
public void Init()
{
// code logic here
}
}
It's possible that this class is being used in some framework which automatically looks for Init
methods and executes them with reflection, but that's not part of the VB language.
See more on this question at Stackoverflow