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.



    Visual C#. NET 2003 Unleashed
    Visual C#. NET 2003 Unleashed
    ISBN: 672326760
    EAN: N/A
    Year: 2003
    Pages: 316

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net