Ich habe diesen C# DLL:F #/.NET Instanz null Kuriosität
namespace TestCSProject
{
public class TestClass
{
public static TestClass Instance = null;
public int Add(int a, int b)
{
if (this == null)
Console.WriteLine("this is null");
return a + b;
}
}
}
Und diesen Fis-App, die die DLL verweist:
open TestCSProject
printfn "%d" (TestClass.Instance.Add(10,20))
Niemand initiiert die Instance
statische Variable. Rate was die Ausgabe der F # App ist?
this is null 30 Press any key to continue . . .
Nach einigen Tests, dass ich herausgefunden habe, wenn ich this
verwenden (beispielsweise Feld zuzugreifen), werde ich NullReferenceExpcetion nicht bekommen.
Ist das ein beabsichtigtes Verhalten oder eine Lücke in F # Compilation/CLR?
+1: oh wow, das ist etwas, was ich noch nie zuvor gesehen habe :) – Juliet