csharp_expressions.md - brainchildservices/curriculum GitHub Wiki

CSHARP EXPRESSIONS(SLIDE TITLE & FRONT HEADING)

SLIDE-1

  • Csharp expressions
    • Expressions are constructed from operands and operators.
    • The operators of an expression indicate which operations to apply to the operands.
    • Examples of operators include +, -, *, /, and new.
    • Examples of operands include literals, fields, local variables, and expressions.

SLIDE-1(DOWNWARDS)

- An expression containing multiple operators 
    - the precedence of the operators controls the order in which the individual operators are evaluated
    - For example, the expression x + y * z is evaluated as x + (y * z) because the * operator has 
      higher precedence than the + operator.

- C# provides a number of operators to perform arithmetic, logical, bitwise and shift operations and equality and order comparisons.

SLIDE-2

  • EXPRESSION CLASSIFICATION
    • A value: Every value has an associated type.
    • A variable: Every variable has an associated type, namely the declared type of the variable.
    • A namespace: An expression with this classification can only appear as the left hand side of a member_access (Member access). In any other context, an expression classified as a namespace causes a compile-time error.
    • A type: An expression with this classification can only appear as the left hand side of a member_access (Member access), or as an operand for the as operator (The as operator), the is operator (The is operator), or the typeof operator (The typeof operator). In any other context, an expression classified as a type causes a compile-time error.

SLIDE-2(DOWNWARDS)

  • A method group: which is a set of overloaded methods resulting from a member lookup (Member lookup). A method group may have an associated instance expression and an associated type argument list. When an instance method is invoked, the result of evaluating the instance expression becomes the instance represented by this (This access). A method group is permitted in an invocation_expression (Invocation expressions) , a delegate_creation_expression (Delegate creation expressions) and as the left hand side of an is operator, and can be implicitly converted to a compatible delegate type (Method group conversions). In any other context, an expression classified as a method group causes a compile-time error.

The final result of an expression is never a namespace, type, method group, or event access. Rather, as noted above, these categories of expressions are intermediate constructs that are only permitted in certain contexts.

SLIDE-3

SLIDE-4

  • CONSTANT EXPRESSION