C#
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
var x = new Example(12);
var y = new Example(34);
var z = Example.Examples.One;
}
}
class Example
{
public static class Examples
{
public static readonly Example Zero = new Example(0);
public static readonly Example One = new Example(1);
}
public readonly Double Value;
public Example(Double Value)
{
this.Value = Value;
}
public static Example Add(Example x, Example y)
{
return new Example(x.Value + y.Value);
}
}
}
VB.net
Option Strict On
Module Module1
Sub Main()
Dim x=New Example(12)
Dim y = New Example(34)
Dim z= Example.Examples.One
End Sub
End Module
Public Class Example
Public Class Examples
Public Shared ReadOnly Zero As Example
Public Shared ReadOnly One As Example
Public Shared ReadOnly Two As Example
Public Shared ReadOnly MinusOne As Example
Shared Sub new()
Zero=New Example(0)
One= New Example(1)
Two = New Example(2)
MinusOne = New Example(-1)
End Sub
End Class
Public ReadOnly Value As Double
Public Sub New(Value As Double)
Me.Value=Value
End Sub
Public Shared Function Add(x As Example,y As Example) As Example
Return New Example(x.Value+y.Value)
End Function
End Class
So OK on to the issue I having.
var z = Example.Examples.One;
if I do a . after the One, I only get the instance methods.
Now if I do the following in VB.net
Dim z= Example.Examples.One.
I not only get the Instance methods but I also get the Examples
Now if this because it is Shared / Static you would also expect the .Add method to be there also but it isn't.
Ideally it should behave the same.
Just to rule out it is an issue with my code, I'll provide an example from .net framework that also has the same behavior. System.Drawing.Color
Where you can do Dim c = Color.Red.Black.Blue.Pink ? That's results in c = Color.Pink.
I've had some rather uninformative answers that it's for compatibility reasons with vb6, but trying find out what those actual reasons are (preferably code examples) is rather like trying to extract information out a Bureaucracy Agency.
- Do you know the reason?
- Can show examples?
- Know how to turn it off.
- Or is there an advantage? to the way VB.net does it?

New Topic/Question
Reply



MultiQuote









|