views:

411

answers:

3

Hi, I'm quite confused about several books in .NET that I have read. Would someone out there like to explain to me what an identifier is and how it differs from a variable? Or variables and identifiers are the same?

Thanks in advance.

A: 

Identifiers are the syntactic means to identify variables. Variables reference memory inside your program where you can store a value or an a reference to an object. An identifier is the grammatical way to indicate this variable. Often the notion of identifiers is more gneral than just for variables. An identfier can also identify a method. So the same gramatical rules that apply in naming variables also apply in naming methods or functions. Classes, methods and variables are all identified by identifiers.

+10  A: 

Identifiers are names you choose to describe your classes, your methods, your variables, and so on.

A variable is referenced to by an identifier, and denotes a memory area that can be manipulated through the use of the identifier.

Luc Touraille
+1, beat me to it but your answer is clear and succinct. ;)
AnthonyWJones
+12  A: 

The difference between a variable and an identifier is the same as between a person and his or her name.

A variable is not an identifier. A variable has an identifier. It also has a type, and (if it is initialized) a value.

For example, the instruction:

bool isClosed = true;

declares and initializes a variable with name (identifier) isClosed, type bool, and value true.

Of course we normally say "isClosed is a variable..." "isClosed has a value of true"... but in the same way as we say "Peter is a software engineer", "John is tired"... that is, we refer to the variable by its name.

Daniel Daranas
Nice comparison!
Luc Touraille
An elaborative explanation, thanks!
KG Sosa
Good example. +1
Brian Rasmussen