Welcome to MSDN Blogs Sign in | Join | Help

Man vs Code

invaluable minutiae

Syndication

'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)

Console.WriteLine(foo[0])]

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

Published Friday, April 27, 2007 10:45 AM by aconrad

Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: 'foo' is a 'variable' but is used like a 'method' @ Monday, July 28, 2008 8:50 PM

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

Mycroft Holmes

# re: 'foo' is a 'variable' but is used like a 'method' @ Monday, December 15, 2008 11:33 AM

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

Chuck

# re: 'foo' is a 'variable' but is used like a 'method' @ Friday, August 21, 2009 11:56 PM

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"].

AMissico

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
Page view tracker