Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Left hand side assignment in C# error

Tags:

c#

vb.net

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
like image 314
user1175857 Avatar asked Mar 22 '26 15:03

user1175857


1 Answers

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

oTP.Session["SomeKey"] = 5;
like image 198
Oded Avatar answered Mar 24 '26 04:03

Oded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!