This question is regarding implicit conversions in VB.Net and C#. The following C# code does not compile:
class Program
{
static void Foo(string s)
{
Console.WriteLine(s);
}
static void Main(string[] args)
{
Foo(3); // Cannot convert from int to string
}
}
The reason being that Foo
expects a parameter of type string, but its given an int. A solution is to replace Foo(3)
with Foo(3.ToString())
. Fine.
Now, the same code authored in VB.Net:
Module Module1
Sub Foo(s As String)
Console.WriteLine(s)
End Sub
Sub Main()
Foo(5)
End Sub
End Module
This compiles and runs just fine!
Question: Why does VB.Net allow this and is there some fundamental difference between VB.Net and C# here?