Page 1 of 6
2. Literals, Variables and Data Types
C# is a strongly typed language. That is:1.
Every variable has a data type.2.
Every expression also has a data type.3.
All assignments are checked for type compatibility.4.
There is no automatic correction or conversion of conflicting data types.5.
The C# compiler checks all the expressions and parameters to ensure that the types are compatible.
: A C# program is a collection of
is a set of declaration statements andmethods. A method has executable statements.2.
: The smallest textual element that cannot be reduced further is called a token. There are 5types of tokens in C#. These are:i)
Punctuation symbolsWhite spaces (space, tab and newline are spaces) and comments are not treated as tokens.3.
: Keywords are reserved words that have a specific meaning in a programming language.These keywords cannot be used as identifiers or variables. C# permits keywords to be used asidentifiers provided the keyword is preceded by the @ symbol. However, this must be avoided.4.
: Identifiers are created by the programmer and are used to give names to classes,methods, variables, namespaces, etc.5.
Literals are constant assigned to variables. Examples of literals are: 250, ‘A’, “Mumbai”.6.
Operators are symbols used in expressions. An operator acts on operands. Someoperators like ‘+’ and ‘*’ require two operands (e.g. 23 + 67), but some operators are unaryoperators because they require only one operand (e.g., the unary minus operator, -23).7.
Symbols such as brackets, semicolon, colon, comma, period, etc are calledpunctuation symbols or
. They are used for grouping statementstogether, or for terminating a statement, etc.8.
A statement is an executable combination of
tokens. A statement in C# ends with thesemicolon symbol (;). Various types of statements in C# are:i)
Declaration statements ii) Expression statements iii) Selection statementsiv) Jump statements v) Interaction statements vi) labeled statementsvii)
Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.