Please have a look at the function below:
Public Function Test(ByVal i As Integer) As Animal
If i = 1 Then
Return New Dog
Else
Return New Cat
End If
End Function
A dog or a cat is returned by the function depending on whether the value of the integer is 1 or not. How is this approached if Dog and Cat are Static classes? i.e. you cannot create an instance of a static class. I have read a few webpages on the MSDN website this afternoon talking about static classes, but I have not found an answer to my specific question.
The term “static class” is a C# concept, it doesn’t exist in VB.NET. So, no, this isn’t possible.
It isn’t possible in C# either, a static class can only derive from Object. The closest VB.NET equivalent of a static class is Module. Quite unsuitable.
You can certainly return a static instance of a class. Declare the variable in a Module or use the Shared keyword if you want to declare it inside a class.