Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
abstract
catch
default
explicit
as
char
delegate
extern
ReservedKeywords
base
bool
break
checked class
const
do
double
else
false
finally
fixed
foreach
goto
if
implicit
is
lock
interface internal
in
add
long
out(generic
object
operator out
modifier)
protected public
readonly ref
short
sizeof
stackalloc static
this
throw
true
try
unchecked unsafe
ushort
using
while
ContextualKeywords
alias
ascending descending dynamic
global
group
null
private
sealed
switch
ulong
volatile
partial
remove
(method)
into
join
select
set
let
byte
continue
enum
float
in(generic
modifier)
namespace
case
decimal
event
for
override
params
return
string
typeof
virtual
sbyte
struct
uint
void
from
get
partial
(type)
orderby
int
new
VALUE TYPES
Type
bool
byte
char
Represents
Range
Default
Value
False
0
'\0'
Booleanvalue
TrueorFalse
8bitunsignedinteger
0to255
16bitUnicodecharacter U+0000toU+ffff
128bitprecisedecimal
decimal valueswith2829
(7.9x1028to7.9x1028)/100to28 0.0M
significantdigits
64bitdoubleprecision (+/)5.0x10324to(+/)1.7x
double
0.0D
floatingpointtype
10308
32bitsingleprecision
float
3.4x1038to+3.4x1038
0.0F
floatingpointtype
int
32bitsignedintegertype 2,147,483,648to2,147,483,647 0
9,223,372,036,854,775,808to
long
64bitsignedintegertype
0L
9,223,372,036,854,775,807
sbyte 8bitsignedintegertype 128to127
0
short 16bitsignedintegertype 32,768to32,767
0
32bitunsignedinteger
uint
0to4,294,967,295
0
type
64bitunsignedinteger
ulong
0to18,446,744,073,709,551,615 0
type
16bitunsignedinteger
ushort
0to65,535
0
type
C#TypeConversionMethods
C#providesthefollowingbuiltintypeconversionmethods:
Sr.No
Methods&Description
ToBoolean
ConvertsatypetoaBooleanvalue,wherepossible.
ToByte
Convertsatypetoabyte.
ToChar
ConvertsatypetoasingleUnicodecharacter,wherepossible.
ToDateTime
Convertsatype(integerorstringtype)todatetimestructures.
ToDecimal
Convertsafloatingpointorintegertypetoadecimaltype.
ToDouble
Convertsatypetoadoubletype.
ToInt16
Convertsatypetoa16bitinteger.
ToInt32
8
9
Convertsatypetoa32bitinteger.
ToInt64
Convertsatypetoa64bitinteger.
ToSbyte
10
Convertsatypetoasignedbytetype.
ToSingle
11
Convertsatypetoasmallfloatingpointnumber.
ToString
12
Convertsatypetoastring.
ToType
13
Convertsatypetoaspecifiedtype.
ToUInt16
14
Convertsatypetoanunsignedinttype.
ToUInt32
15
Convertsatypetoanunsignedlongtype.
ToUInt64
16
Type
Integral
types
Convertsatypetoanunsignedbiginteger.
Example
sbyte,byte,short,ushort,int,uint,long,ulong,andchar
Floating
floatanddouble
pointtypes
Decimal
types
Boolean
types
Nullable
types
decimal
trueorfalsevalues,asassigned
Nullabledatatypes
Escapesequence
Meaning
\\
\character
\'
'character
\"
"character
\?
?character
\a
Alertorbell
\b
Backspace
\f
Formfeed
\n
Newline
\r
Carriagereturn
\t
Horizontaltab
\v
\xhh...
Verticaltab
Hexadecimalnumberofoneormoredigits
Arithmetic Operators
Operator
+
*
/
%
++
Description
Addstwooperands
Subtractssecondoperandfromthefirst
Multipliesbothoperands
Dividesnumeratorbydenumerator
ModulusOperatorandremainderofafteraninteger
division
Incrementoperatorincreasesintegervaluebyone
Decrementoperatordecreasesintegervaluebyone
Example
A+B=30
AB=10
A*B=200
B/A=2
B%A=0
A++=11
A=9
Rational Operators
Operator
==
!=
>
<
>=
<=
Description
Example
Checksifthevaluesoftwooperandsareequalornot,if
(A==B)isnottrue.
yesthenconditionbecomestrue.
Checksifthevaluesoftwooperandsareequalornot,if
(A!=B)istrue.
valuesarenotequalthenconditionbecomestrue.
Checksifthevalueofleftoperandisgreaterthanthe
(A>B)isnottrue.
valueofrightoperand,ifyesthenconditionbecomestrue.
Checksifthevalueofleftoperandislessthanthevalue
(A<B)istrue.
ofrightoperand,ifyesthenconditionbecomestrue.
Checksifthevalueofleftoperandisgreaterthanorequal
tothevalueofrightoperand,ifyesthencondition
(A>=B)isnottrue.
becomestrue.
Checksifthevalueofleftoperandislessthanorequalto
thevalueofrightoperand,ifyesthenconditionbecomes (A<=B)istrue.
true.
Logical Operators
Operator
&&
||
!
Description
Example
CalledLogicalANDoperator.Ifboththeoperandsare
(A&&B)isfalse.
nonzerothenconditionbecomestrue.
CalledLogicalOROperator.Ifanyofthetwooperandsis
(A||B)istrue.
nonzerothenconditionbecomestrue.
CalledLogicalNOTOperator.Usetoreversesthelogical
stateofitsoperand.IfaconditionistruethenLogical
!(A&&B)istrue.
NOToperatorwillmakefalse.
Bitwise Operators
p
0
0
1
1
q
0
1
1
0
p&q
0
0
1
0
p|q
0
1
1
1
p^q
0
1
0
1
Operator
&
|
^
~
<<
>>
Description
Example
BinaryANDOperatorcopiesabittotheresultifitexists
(A&B)=12,whichis00001100
inbothoperands.
BinaryOROperatorcopiesabitifitexistsineither
(A|B)=61,whichis00111101
operand.
BinaryXOROperatorcopiesthebitifitissetinone
(A^B)=49,whichis00110001
operandbutnotboth.
(~A)=61,whichis11000011in2's
BinaryOnesComplementOperatorisunaryandhasthe
complementduetoasignedbinary
effectof'flipping'bits.
number.
BinaryLeftShiftOperator.Theleftoperandsvalueis
movedleftbythenumberofbitsspecifiedbytheright
A<<2=240,whichis11110000
operand.
BinaryRightShiftOperator.Theleftoperandsvalueis
movedrightbythenumberofbitsspecifiedbytheright A>>2=15,whichis00001111
operand.
Assignment Operators
Operator
=
+=
*=
/=
%=
Description
Example
Simpleassignmentoperator,Assigns
valuesfromrightsideoperandstoleftside C=A+BassignsvalueofA+BintoC
operand
AddANDassignmentoperator,Itadds
rightoperandtotheleftoperandandassign C+=AisequivalenttoC=C+A
theresulttoleftoperand
SubtractANDassignmentoperator,It
subtractsrightoperandfromtheleft
operandandassigntheresulttoleft
operand
C=AisequivalenttoC=CA
MultiplyANDassignmentoperator,It
multipliesrightoperandwiththeleft
C*=AisequivalenttoC=C*A
operandandassigntheresulttoleft
operand
DivideANDassignmentoperator,It
dividesleftoperandwiththerightoperand C/=AisequivalenttoC=C/A
andassigntheresulttoleftoperand
ModulusANDassignmentoperator,It
takesmodulususingtwooperandsand
C%=AisequivalenttoC=C%A
assigntheresulttoleftoperand
<<=
LeftshiftANDassignmentoperator
C<<=2issameasC=C<<2
>>=
RightshiftANDassignmentoperator
C>>=2issameasC=C>>2
&=
BitwiseANDassignmentoperator
C&=2issameasC=C&2
^=
|=
bitwiseexclusiveORandassignment
operator
bitwiseinclusiveORandassignment
operator
Miscellaneous Operators
C^=2issameasC=C^2
C|=2issameasC=C|2
Operator
Description
sizeof() Returnsthesizeofadatatype.
typeof() Returnsthetypeofaclass.
Example
sizeof(int),returns4.
typeof(StreamReader);
&
Returnstheaddressofanvariable.
&a;returnsactualaddressofthevariable.
Pointertoavariable.
*a;createspointernamed'a'toavariable.
?:
ConditionalExpression
IfConditionistrue?ThenvalueX:
OtherwisevalueY
is
Determineswhetheranobjectisofacertaintype.
If(FordisCar)//checksifFordisan
objectoftheCarclass.
Objectobj=newStringReader("Hello");
as
Castwithoutraisinganexceptionifthecastfails.
StringReaderr=objasStringReader;
Operator Precedence
Category
Operator
Associativity
Postfix
()[]>.++
Lefttoright
Unary
+!~++(type)*&sizeof
Righttoleft
Multiplicative
*/%
Lefttoright
Additive
Lefttoright
Shift
<<>>
Lefttoright
Relational
<<=>>=
Lefttoright
Equality
==!=
Lefttoright
BitwiseAND
&
Lefttoright
BitwiseXOR
Lefttoright
BitwiseOR
LogicalAND
LogicalOR
|
&&
||
Lefttoright
Lefttoright
Lefttoright
Conditional
?:
Righttoleft
Assignment
=+==*=/=%=>>=<<=&=^=|=
Righttoleft
Comma
Lefttoright
Decision Making
Statement
Description
ifstatement
Anifstatementconsistsofabooleanexpression
followedbyoneormorestatements.
if...elsestatement
Anifstatementcanbefollowedbyanoptionalelse
statement,whichexecuteswhenthebooleanexpression
isfalse.
nestedifstatements
Youcanuseoneiforelseifstatementinsideanotherif
orelseifstatement(s).
switchstatement
Aswitchstatementallowsavariabletobetestedfor
equalityagainstalistofvalues.
nestedswitchstatements
Youcanuseoneswitchstatementinsideanotherswitch
statement(s).
Loop Type
whileloop
forloop
do...whileloop
nestedloops
Control Statement
breakstatement
continuestatement
Description
It repeats a statement or a group of statements
while a given condition is true. It tests the
condition before executing the loop body.
It executes a sequence of statements multiple
times and abbreviates the code that manages
the loop variable.
It is similar to a while statement, except that it
tests the condition at the end of the loop body
You can use one or more loop inside any another
while, for or do..while loop.
Description
Terminates the loop or switch statement and
transfers execution to the statement immediately
following the loop or switch.
Causes the loop to skip the remainder of its body
and immediately retest its condition prior to
reiterating.
Arrays
Concept
Multidimensionalarrays
Jaggedarrays
Passingarraystofunctions
Paramarrays
TheArrayClass
Description
C# supports multidimensional arrays. The
simplest form of the multidimensional array is
the two-dimensional array.
C# supports multidimensional arrays, which are
arrays of arrays.
You can pass to the function a pointer to an array
by specifying the array's name without an index.
This is used for passing unknown number of
parameters to a function.
Defined in System namespace, it is the base
class to all arrays, and provides various
properties and methods for working with arrays.
Sr.N
o
Methods
public static int Compare(string strA, string strB)
Comparestwospecifiedstringobjectsandreturnsanintegerthatindicatestheirrelativepositionin
thesortorder.
Concatenatesthreestringobjects.
Concatenatesfourstringobjects.
9
10
11
Replacesoneormoreformatitemsinaspecifiedstringwiththestringrepresentationofa
specifiedobject.
14
ReturnsthezerobasedindexofthefirstoccurrenceofthespecifiedUnicodecharacterinthe
currentstring.
ReturnsthezerobasedindexofthefirstoccurrenceofthespecifiedUnicodecharacterinthis
string,startingsearchatthespecifiedcharacterposition.
Returnsthezerobasedindexofthefirstoccurrenceofthespecifiedstringinthisinstance,starting
searchatthespecifiedcharacterposition.
Returnsthezerobasedindexofthefirstoccurrenceinthisinstanceofanycharacterinaspecified
arrayofUnicodecharacters.
Returnsthezerobasedindexofthefirstoccurrenceinthisinstanceofanycharacterinaspecified
arrayofUnicodecharacters,startingsearchatthespecifiedcharacterposition.
19
currentstringobject.
20
21
22
ReturnsthezerobasedindexpositionofthelastoccurrenceofthespecifiedUnicodecharacter
withinthecurrentstringobject.
Returnsthezerobasedindexpositionofthelastoccurrenceofaspecifiedstringwithinthecurrent
stringobject.
Removesallthecharactersinthecurrentinstance,beginningataspecifiedpositionandcontinuing
throughthelastposition,andreturnsthestring.
Removesthespecifiednumberofcharactersinthecurrentstringbeginningataspecifiedposition
andreturnsthestring.
ReplacesalloccurrencesofaspecifiedUnicodecharacterinthecurrentstringobjectwiththe
specifiedUnicodecharacterandreturnsthenewstring.
Replacesalloccurrencesofaspecifiedstringinthecurrentstringobjectwiththespecifiedstring
andreturnsthenewstring.
Returnsastringarraythatcontainsthesubstringsinthecurrentstringobject,delimitedby
elementsofaspecifiedUnicodecharacterarray.
30
ofsubstringstoreturn.
31
32
34
35
36
ReturnsaUnicodecharacterarraywithallthecharactersinthecurrentstringobject,startingfrom
thespecifiedindexanduptothespecifiedlength.