2

I am converting some VB code into C#. In VB the code looks like the following:

oTP.CreateObject("SomeInterop")    
oTP.Session("SomeKey") = 5

In C#, if I do:

oTP.Session("SomeKey") = 5;

I get a compilation error, "The left-hand side of an assignment must be a variable, property or indexer". In VB, oTP is declared as an object and in C#, i declared it as dynamic. In the oTP code, Session looks like this:

Public Property Session(ByVal VariableName As String) As Object
Get
....
End Get
Set(ByVal Value As Object)
.....
End Set
4

1 回答 1

10

The syntax for indexers in C# is different - you need to use square braces:

oTP.Session["SomeKey"] = 5;
于 2012-07-27T19:13:16.810 回答