Victor Oliveira
Victor Oliveira

Reputation: 3713

Whats the difference between Field and Variable?

I've been using Visual studio to develop a C++ application. I'm not an expert in C++, neither other languages derived from C like C#. So, studying visual studio's symbology I found a reference for the same symbol saying "Field or Variable". Correct if I'm wrong please, but this sounds to me pretty almost like "Method or Function" definition.

In C++ there are no methods, instead they are commonly called as functions. So, in C++ there are also no Fields, it's a particularity from C# which works like a variable except that it should be private and it needs to be accessed from a "Get" call. Am I wrong?

Upvotes: 8

Views: 6756

Answers (1)

Servy
Servy

Reputation: 203844

Not all variables are fields. Local variables of a method are variables, but not fields. Parameters to a method, property, constructor, or anonymous method are variables, but are not fields.

Not all fields are variables. A const member is technically a field, but it is not a variable.

Upvotes: 6

Related Questions