This documentation is archived and is not being maintained.

CodeVariable.IsConstant Property

Gets or sets whether or not the item is a constant.

Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)

bool IsConstant { get; set; }
/** @property */
boolean get_IsConstant ()

/** @property */
void set_IsConstant (boolean pIsConstant)

function get IsConstant () : boolean

function set IsConstant (pIsConstant : boolean)

Property Value

A Boolean value indicating true if the item is a constant; false otherwise.

IsConstant returns whether or not the storage location represented by this code variable can be set.


The values of code model elements such as classes, structs, functions, attributes, delegates, and so forth can be non-deterministic after making certain kinds of edits, meaning that their values cannot be relied upon to always remain the same. For more information, see the section Code Model Element Values Can Change in Discovering Code with the Code Model (Visual Basic).

public void IsConstantExample(DTE2 dte)
    // Before running this example, open a code document from a project
    // and place the insertion point inside a variable definition.
        // Retrieve the CodeVariable at the insertion point.
        TextSelection sel = 
        CodeVariable var = 

        // Display whether the variable is a constant.
        if (var.IsConstant)
            MessageBox.Show(var.Name + " is a constant.");
            MessageBox.Show(var.Name + " is not a constant.");
    catch (Exception ex)