Tuesday, July 12, 2011

Object Property Missing When Converting to C# from VB

I recently ran into a problem when attempt to convert a method from VB to C#.  In the old code I was able to reference the Field property in VB with the following notation:

myObjectVariable.Field("DESCRIPTION") = "Description - testing - please ignore"

Yet I could not figure out how to translate that to C# syntax because the compiler would not recognize a similar property.  Finally, I figured it out.  Here is the C# equivalent:

myObjectVariable[“DESCRIPTION”] = “Description – testing – please ignore”

I believe that also works with "Item" too.

VB.NET:
myObjectVariable.Item("DESCRIPTION") = "Description - testing - please ignore"

C#:
myObjectVariable[“DESCRIPTION”] = “Description – testing – please ignore”