Search code examples
.netvariablesidentifier

Identifiers or Variables: Which is which?


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.


Solution

  • 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.