Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 750
Victor R. Oliveira Avatar asked Sep 10 '14 14:09

Victor R. Oliveira


People also ask

What is the difference between a field and local variable?

An instance field is the same as a class field, but is non static and can be different for each instance of the object. And a local variable is a variable inside a method or block, that can only be used by that method or block.

Is variable and field are same in Java?

Fields − Variables of a class i.e. instance variables and static variables are called fields. They can't be abstract except this you can use any other modifier with fields.

What is meant by field variable?

Field variables are variables that are declared as a member of a class or declared outside any method or constructor within the class.

What is the difference between field and variable in C#?

Variables represent storage locations. Every variable has a type that determines what values can be stored in the variable. More about variables. A field is a variable of any type that is declared directly in a class or struct.


1 Answers

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.

like image 82
Servy Avatar answered Sep 28 '22 22:09

Servy