我有一個變量fsharp互動Fsharp互動福
val toto : obj = [["NKY INDEX"]]
(我接到了一個電話到正規的dotnet庫值,其原型告訴我,它返回一個OBJ)
我想要訪問它裏面的值,但我不知道類型。 所以我儘量體現它:
>toto.GetType();;
val it : Type =
System.Object[,]
{Assembly = mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;
AssemblyQualifiedName = "System.Object[,], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
Attributes = AutoLayout, AnsiClass, Class, Public, Sealed, Serializable;
BaseType = System.Array;
ContainsGenericParameters = false;
CustomAttributes = seq [[System.SerializableAttribute()]];
DeclaredConstructors = [|Void .ctor(Int32, Int32);
Void .ctor(Int32, Int32, Int32, Int32)|];
DeclaredEvents = [||];
DeclaredFields = [||];
DeclaredMembers = [|Void Set(Int32, Int32, System.Object);
System.Object& Address(Int32, Int32);
System.Object Get(Int32, Int32);
Void .ctor(Int32, Int32);
Void .ctor(Int32, Int32, Int32, Int32)|];
DeclaredMethods = [|Void Set(Int32, Int32, System.Object);
System.Object& Address(Int32, Int32);
System.Object Get(Int32, Int32)|];
DeclaredNestedTypes = seq [];
DeclaredProperties = [||];
它有一個Get方法,然而,當我嘗試檢索元素,我得到一個錯誤。
>toto.Get(0,0);;
toto.Get(0,0);;
-----^^^
error FS0039: The field, constructor or member 'Get' is not defined
什麼是檢索內部元素的正確方法?
PS:鑄造事前得到相同的
>(toto :?> System.Object[,]).Get(0,0);;
(toto :?> System.Object[,]).Get(0,0);;
----------------------------^^^
error FS0039: The field, constructor or member 'Get' is not defined
同爲[0,0]
> toto.[0, 0];;
toto.[0, 0];;
^^^^^^^^^^^
error FS0039: The field, constructor or member 'Item' is not defined
表達式'toto:obj = [[「」]]'不應該編譯。 – JaredPar 2012-03-09 18:38:44
這是不幸的後果列表和多維數組的列表以FSI – desco 2012-03-09 18:41:50
@JaredPar類似的方式打印我沒有提及,因爲我認爲顯示的信息是足夠的,我從一個dotnet函數調用得到這個值。他的所有榮耀中的歸來類型是對象...... – nicolas 2012-03-09 20:02:40