Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
6Activity
0 of .
Results for:
No results containing your search query
P. 1
C# - Chap 2

C# - Chap 2

Ratings:

4.0

(1)
|Views: 692 |Likes:
Published by MukeshTekwani
Lecture notes on programming language c#, (c sharp). Notes developed by Prof Mukesh N Tekwani, Mumbai. These notes are as per the latest syllabus of University of Mumbai , for B.Sc (IT) - Sem VI
Lecture notes on programming language c#, (c sharp). Notes developed by Prof Mukesh N Tekwani, Mumbai. These notes are as per the latest syllabus of University of Mumbai , for B.Sc (IT) - Sem VI

More info:

Published by: MukeshTekwani on Mar 31, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

09/02/2010

pdf

text

original

 
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.
Important Definitions:
1.
 
Class
: A C# program is a collection of 
classes
. A
class
is a set of declaration statements andmethods. A method has executable statements.2.
 
Token
: The smallest textual element that cannot be reduced further is called a token. There are 5types of tokens in C#. These are:i)
 
Keywordsii)
 
Identifiersiii)
 
Literalsiv)
 
Operatorsv)
 
Punctuation symbolsWhite spaces (space, tab and newline are spaces) and comments are not treated as tokens.3.
 
Keywords
: 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
: Identifiers are created by the programmer and are used to give names to classes,methods, variables, namespaces, etc.5.
 
Literals
:
 
Literals are constant assigned to variables. Examples of literals are: 250, ‘A’, “Mumbai”.6.
 
Operators:
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.
 
Punctuation Symbols:
Symbols such as brackets, semicolon, colon, comma, period, etc are calledpunctuation symbols or
punctuators
or
separators
. They are used for grouping statementstogether, or for terminating a statement, etc.8.
 
Statements:
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)
 
Empty statements
Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.
 
Prof. Mukesh N. Tekwani Email: mukeshtekwani@hotmail.comPage 2 of 6
Keywords :
C# has 76 keywords. A few commonly used keywords are listed below:break constcase falsecatch inclass newcontinue nulldo objectelse privatefor publicforeach returngoto structif trueswitch voidtry while
Literals:
Literals are value constants assigned to variables. The various types of literals in C# are as follows:
1.
 
Numeric Literals
a.
 
Integer Literals -- e.g., 250, 200, -187, 0, 0xcab (hexadecimal literal)b.
 
Real Literals -- e.g., 3.142, -96.4, 0.0074, 6.023E+32.
 
Boolean Literals
-- e.g., true, false
3.
 
Character Literals
a.
 
Single character literals -- e.g., ‘A’, ‘4’ , ‘?’, b.
 
String literals -- e.g., “Welcome 2009”, “Hello”, “9869012345”c.
 
Backslash Character Literals -- These are the escape sequences. They are used forformatting the printed output. The most commonly used escape sequences are:i.
 
‘\n’ -- new line characterii.
 
‘\b’ -- back spaceiii.
 
‘\f’ -- form feediv.
 
’\t’ -- horizontal tabv.
 
’\v’ -- vertical tab
Variables:
1.
 
A variable is a named data storage location.2.
 
A variable is an identifier created by the programmer.3.
 
A variable refers to some storage location in the computer’s memory.boolbytechardecimaldoublefloatintlongsbyteshortstringulongushort
Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.
 
2. Programming in C#Page 3 of 64.
 
The value of a variable can change during the execution of a program.5.
 
Every variable has a data type. E.g., an int variable can only store integer type data, etc.6.
 
The place at which a variable is declared determines the scope of that variable in the program.7.
 
All variable must be declared before they are used in a program.8.
 
The data type of a variable determines the following:a.
 
The
space
occupied in the memory by the variable. E.g., in C#,
int 
occupies 4 bytes.b.
 
The
operations
that can be carried out on that variable. E.g., we can carry out the operationof % (modulus) on integer operands but not on
char 
operands.c.
 
The
range
of values that can be stored in the variable.
Rules for forming variable names:
1.
 
The variable name should be meaningful.2.
 
The first character must be a letter.3.
 
Remaining characters can be letters, digits or underscore (_).4.
 
C# is case-sensitive. That is, the variable
 MARKS
and
 marks
are different.5.
 
C# keywords cannot be used as variable names.Here are some examples of valid and invalid variable names. For each keyword, write “Valid” or“Invalid”. If it is invalid, justify.Variable Name Valid/Invalid Reason if invalidmarksmks in javaforbalance$balance2paperstax_paid
Data Types:
C# supports two types of data types. These are:1.
 
Value types, and2.
 
Reference Types.
1.
 
Value types :-
i)
 
These are of fixed length.ii)
 
They are stored on a stack.iii)
 
When a variable is assigned to another variable, the values are actually copied.
Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Activity (6)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
nagadgv2004 liked this
capy56 liked this
girish3210 liked this
ASHA_ssdn liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->