Team LiB
Previous Section Next Section

Basic Expressions

An expression is defined as a syntactically correct program statement. However, for the purpose of this chapter, the expressions we're most interested in revolve around assignment and evaluation, and true/false determination. An assignment expression has at least one variable and one value to be assigned to that variable. Such is the case of declaring an integer value and assigning it the default value of 10. All variables must be initialized before use; otherwise, the C# compiler will bitterly complain about the usage of an uninitialized variable. So, what does this mean exactly? Take a look at the following C# statements :

int i;         //C# complains about the uninitialized variable 
int j = 10;    //variable j has the initial value of 10
int k;
k = 10;        //okay as long as done before usage of k

C# requires all variables to be initialized before usage. The variable can be initialized during declaration or before its first usage. However, it's best to initialize a default value during its declaration; doing so will aid in future debugging attempts.

    Team LiB
    Previous Section Next Section