‘foo’ is a ‘variable’ but is used like a ‘method’


Over the last several months, because of my current project I have had to program in a bunch of different languages.   (The reason for this will become crystal clear early next week).  Basically, I have had to code in C#, VB, and IronPython while at the same time I have been trying learning Haskell and occasionally Ruby - and some Javascript just for fun on the weekends.  To be brutally honest, this is a major pain.

For example, the difference in the syntax for calling indexers between VB and C#

Dim foo As List(Of String) = New List(Of String)


Will not compile with the error - "Error 18 Identifier expected."

If I use the VB syntax in C#, I get my new favorite error: 'foo' is a 'variable' but is used like a 'method'

Particular annoying is the differences in For Each between C#, VB, and Python - each which has a slightly different syntax.  For some reason this has been tripping me up a lot during live demos. 

Interestingly, the whole curly brace versus END statements versus tabs (python) deal doesn't bother me at all.  Although, this shocked me.

kick it on DotNetKicks.com

Comments (3)
  1. Mycroft Holmes says:

    What a useless peice of information, I come here looking for a solution and get… nothing

  2. Chuck says:

    I second that motion.   This helps me not.  IF anyone has any suggestions to solve, please post, as I have the same issue.

  3. AMissico says:

    It is because foo(0) is for VB.NET and foo[0] is for C#. Therefore, if you are using C# and getting this compiler error then you need to look for the syntax error. In my case it was dr("fieldName") instead of dr["fieldName"].

Comments are closed.

Skip to main content