PrimitivePrimitive DataData TypesTypes andand VariablesVariables CreatingCreating andand RunningRunning YourYour FirstFirst #C# ProgramProgram

SvetlinSvetlin NakovNakov Telerik Corporation www.telerik.com TableTable ofof ContentsContents

1. PrimitivePrimitive DataData TypesTypes  IntegerInteger  Floating-PointFloating-Point // DecimalDecimal Floating-PointFloating-Point  BooleanBoolean  CharacterCharacter  StringString  ObjectObject 2. DeclaringDeclaring andand UsingUsing VariablesVariables  IdentifiersIdentifiers  DeclaringDeclaring VariablesVariables andand AssigningAssigning ValuesValues  LiteralsLiterals P NullableNullable typestypes

2 PrimitivePrimitive DataData TypesTypes HowHow ComputingComputing Works?Works?

 ComputersComputers areare machinesmachines thatthat processprocess datadata  DataData isis storedstored inin thethe computercomputer memorymemory inin variablesvariables  VariablesVariables havehave namename,, datadata typetype andand valuevalue  ExampleExample ofof variablevariable definitiondefinition andand assignmentassignment inin C#C# VariableVariable namename

DataData typetype int count = 5;

VariableVariable valuevalue 4 WhatWhat IsIs aa DataData Type?Type?  AA datadata typetype::  IsIs aa domaindomain ofof valuesvalues ofof similarsimilar characteristicscharacteristics  DefinesDefines thethe typetype ofof informationinformation storedstored inin thethe computercomputer memorymemory (in(in aa variable)variable)  Examples:Examples:  PositivePositive integers:integers: 11,, 22,, 33,, ……  AlphabeticalAlphabetical characters:characters: aa,, bb,, cc,, ……  DaysDays ofof week:week: MondayMonday,, TuesdayTuesday,, ……

5 DataData TypeType CharacteristicsCharacteristics  AA datadata typetype has:has:  NameName (C#(C# keywordkeyword oror .NET.NET type)type)  SizeSize (how(how muchmuch memorymemory isis used)used)  DefaultDefault valuevalue  Example:Example:  IntegerInteger numbersnumbers inin C#C#  Name:Name: intint  Size:Size: 3232 bitsbits (4(4 )bytes)  DefaultDefault value:value: 00

6 IntegerInteger TypesTypes WhatWhat areare IntegerInteger Types?Types?  IntegerInteger types:types:  RepresentRepresent wholewhole numbersnumbers  MayMay bebe signedsigned oror unsignedunsigned  HaveHave rangerange ofof values,values, dependingdepending onon thethe sizesize ofof memorymemory usedused  TheThe defaultdefault valuevalue ofof integerinteger typestypes is:is:  00 –– forfor integerinteger types,types, exceptexcept  0L0L –– forfor thethe longlong typetype

8 IntegerInteger TypesTypes  IntegerInteger typestypes are:are:  sbytesbyte (-128(-128 toto 127):127): signedsigned 8-bit8-  bytebyte (0(0 toto 255):255): unsignedunsigned 8-bit8-bit  shortshort (-32,768(-32,768 toto 32,767):32,767): signedsigned 16-bit16-bit  ushortushort (0(0 toto 65,535):65,535): unsignedunsigned 16-bit16-bit  intint (-2,147,483,648(-2,147,483,648 toto 2,147,483,647):2,147,483,647): signedsigned 32-bit32-bit  uintuint (0(0 toto 4,294,967,295):4,294,967,295): unsignedunsigned 32-bit32-bit

9 IntegerInteger TypesTypes (2)(2)  MoreMore integerinteger types:types:  longlong (-9,223,372,036,854,775,808(-9,223,372,036,854,775,808 toto 9,223,372,036,854,775,807):9,223,372,036,854,775,807): signedsigned 64-bit64-bit  ulongulong (0(0 toto 18,446,744,073,709,551,615):18,446,744,073,709,551,615): unsignedunsigned 64-bit64-bit

10 MeasuringMeasuring TimeTime –– ExampleExample  DependingDepending onon thethe unitunit ofof measuremeasure wewe maymay useuse differentdifferent datadata types:types:

centuries = 20; // Usually a small number ushort years = 2000; uint days = 730480; ulong hours = 17531520; // May be a very big number Console.WriteLine("{0} centuries is {1} years, or {2} days, or {3} hours.", centuries, years, days, hours);

11 IntegerInteger TypesTypes LiveLive DemoDemo Floating-PointFloating-Point andand DecimalDecimal Floating-PointFloating-Point TypesTypes WhatWhat areare Floating-PointFloating-Point Types?Types?  Floating-pointFloating-point types:types:  RepresentRepresent realreal numbersnumbers  MayMay bebe signedsigned oror unsignedunsigned  HaveHave rangerange ofof valuesvalues andand differentdifferent precisionprecision dependingdepending onon thethe usedused memorymemory  CanCan behavebehave abnormallyabnormally inin thethe calculationscalculations

14 Floating-PointFloating-Point TypesTypes  Floating-pointFloating-point typestypes are:are:  floatfloat (±1.5(±1.5 ×× 1010−45 toto ±3.4±3.4 ×× 101038):): 32-,32-bits, precisionprecision ofof 77 digitsdigits  doubledouble (±5.0(±5.0 ×× 1010−324 toto ±1.7±1.7 ×× 1010308):): 64-bits,64-bits, precisionprecision ofof 15-1615-16 digitsdigits  TheThe defaultdefault valuevalue ofof floating-pointfloating-point types:types:  IsIs 0.0F0.0F forfor thethe floatfloat typetype  IsIs 0.0D0.0D forfor thethe doubledouble typetype

15 PIPI PrecisionPrecision –– ExampleExample

 SeeSee belowbelow thethe differencedifference inin precisionprecision whenwhen usingusing floatfloat andand doubledouble::

float floatPIfloatPI = 3.141592653589793238f; double doublePI = 3.141592653589793238; Console.WriteLine("Float PI is: {0}", floatPI); Console.WriteLine("Double PI is: {0}", doublePI);

 NOTE:NOTE: TheThe ““ff”” suffixsuffix inin thethe firstfirst statement!statement!  RealReal numbersnumbers areare byby defaultdefault interpretedinterpreted asas doubledouble!!  OneOne shouldshould explicitlyexplicitly convertconvert themthem toto floatfloat 16 AbnormalitiesAbnormalities inin thethe Floating-PointFloating-Point CalculationsCalculations  SometimesSometimes abnormalitiesabnormalities cancan bebe observedobserved whenwhen usingusing floating-pointfloating-point numbersnumbers  ComparingComparing floating-pointfloating-point numbersnumbers cancan notnot bebe performedperformed directlydirectly withwith thethe ==== operatoroperator  Example:Example:

double a = 1.0f; double b = 0.33f; double sum = 1.33f; bool equal = (a+b == sum); // False!!! Console.WriteLine("a+b={0} sum={1} equal={2}", a+b, sum, equal);

17 DecimalDecimal Floating-PointFloating-Point TypesTypes  ThereThere isis aa specialspecial decimaldecimal floating-pointfloating-point realreal numbernumber typetype inin C#:C#:  decimaldecimal (±1,0(±1,0 ×× 1010-28 toto ±7,9±7,9 ×× 101028):): 128-bits,128-bits, precisionprecision ofof 28-2928-29 digitsdigits  UsedUsed forfor financialfinancial calculationscalculations  NoNo round-offround-off errorserrors  AlmostAlmost nono lossloss ofof precisionprecision  TheThe defaultdefault valuevalue ofof decimaldecimal typetype is:is:  0.00.0MM ((MM isis thethe suffixsuffix forfor decimaldecimal numbers)numbers)

18 Floating-PointFloating-Point andand DecimalDecimal Floating-PointFloating-Point TypesTypes LiveLive DemoDemo BooleanBoolean TypeType TheThe BooleanBoolean DataData TypeType  TheThe BooleanBoolean datadata typetype::  IsIs declareddeclared byby thethe boolbool keywordkeyword  HasHas twotwo possiblepossible values:values: truetrue andand falsefalse  IsIs usefuluseful inin logicallogical expressionsexpressions  TheThe defaultdefault valuevalue isis falsefalse

21 BooleanBoolean ValuesValues –– ExampleExample  ExampleExample ofof booleanboolean variablesvariables takingtaking valuesvalues ofof truetrue oror falsefalse::

int a = 1; int b = 2; bool greaterAB = (a > b); Console.WriteLine(greaterAB); // False bool equalA1 = (a == 1); Console.WriteLine(equalA1); // True

22 BooleanBoolean TypeType LiveLive DemoDemo CharacterCharacter TypeType TheThe CharacterCharacter DataData TypeType  TheThe charactercharacter datadata typetype::  RepresentsRepresents symbolicsymbolic informationinformation  IsIs declareddeclared byby thethe charchar keywordkeyword  GivesGives eacheach symbolsymbol aa correspondingcorresponding integerinteger codecode  HasHas aa '\0''\0' defaultdefault valuevalue  TakesTakes 1616 bitsbits ofof memorymemory (from(from U+0000U+0000 toto U+FFFFU+FFFF))

25 CharactersCharacters andand CodesCodes  TheThe exampleexample belowbelow showsshows thatthat everyevery symbolsymbol hashas anan itsits uniqueunique UnicodeUnicode code:code:

char symbol = 'a'; Console.WriteLine("The code of '{0}' is: {1}", symbol, (int) symbol); symbol = 'b'; Console.WriteLine("The code of '{0}' is: {1}", symbol, (int) symbol); symbol = 'A'; Console.WriteLine("The code of '{0}' is: {1}", symbol, (int) symbol);

26 CharacterCharacter TypeType LiveLive DemoDemo StringString TypeType TheThe StringString DataData TypeType  TheThe stringstring datadata typetype::  RepresentsRepresents aa sequencesequence ofof characterscharacters  IsIs declareddeclared byby thethe stringstring keywordkeyword  HasHas aa defaultdefault valuevalue nullnull (no(no value)value)  StringsStrings areare enclosedenclosed inin quotes:quotes:

string s = "Microsoft .NET Framework";  StringsStrings cancan bebe concatenatedconcatenated  UsingUsing thethe ++ operatoroperator

29 SayingSaying HelloHello –– ExampleExample  ConcatenatingConcatenating thethe twotwo namesnames ofof aa personperson toto obtainobtain hishis fullfull name:name:

string firstName = "Ivan"; string lastName = "Ivanov"; Console.WriteLine("Hello, {0}!\n", firstName);

string fullName = firstName + " " + lastName; Console.WriteLine("Your full name is {0}.", fullName);

 NOTE:NOTE: aa spacespace isis missingmissing betweenbetween thethe twotwo names!names! WeWe havehave toto addadd itit manuallymanually 30 StringString TypeType LiveLive DemoDemo ObjectObject TypeType TheThe ObjectObject TypeType  TheThe objectobject type:type:  IsIs declareddeclared byby thethe objectobject keywordkeyword  IsIs thethe basebase typetype ofof allall otherother typestypes  CanCan holdhold valuesvalues ofof anyany typetype

33 UsingUsing ObjectsObjects  ExampleExample ofof anan objectobject variablevariable takingtaking differentdifferent typestypes ofof data:data:

object dataContainer = 5; Console.Write("The value of dataContainer is: "); Console.WriteLine(dataContainer);

dataContainer = "Five"; Console.Write("The value of dataContainer is: "); Console.WriteLine(dataContainer);

34 ObjectsObjects LiveLive DemoDemo pp qq i

IntroducingIntroducing VariablesVariables WhatWhat IsIs aa Variable?Variable?  AA variablevariable isis a:a:  PlaceholderPlaceholder ofof informationinformation thatthat cancan usuallyusually bebe changedchanged atat run-timerun-time  VariablesVariables allowallow youyou to:to:  StoreStore informationinformation  RetrieveRetrieve thethe storedstored informationinformation  ManipulateManipulate thethe storedstored informationinformation

37 VariableVariable CharacteristicsCharacteristics  AA variablevariable has:has:  NameName  TypeType (of(of storedstored data)data)  ValueValue  Example:Example: int counter = 5;  Name:Name: countercounter  Type:Type: intint  Value:Value: 55

38 DeclaringDeclaring AndAnd UsingUsing VariablesVariables DeclaringDeclaring VariablesVariables  WhenWhen declaringdeclaring aa variablevariable we:we:  SpecifySpecify itsits typetype  SpecifySpecify itsits namename (called(called identifier)identifier)  MayMay givegive itit anan initialinitial valuevalue  TheThe syntaxsyntax isis thethe following:following:

[= ];  Example:Example:

int height = 200;

40 IdentifiersIdentifiers  IdentifiersIdentifiers maymay consistconsist of:of:  LettersLetters (Unicode)(Unicode)  DigitsDigits [0-9][0-9]  UnderscoreUnderscore "_""_"  IdentifiersIdentifiers  CanCan beginbegin onlyonly withwith aa letterletter oror anan underscoreunderscore  CannotCannot bebe aa C#C# keywordkeyword

41 IdentifiersIdentifiers (2)(2)  IdentifiersIdentifiers  ShouldShould havehave aa descriptivedescriptive namename  ItIt isis recommendedrecommended toto useuse onlyonly LatinLatin lettersletters  ShouldShould bebe neitherneither tootoo longlong nornor tootoo shortshort  Note:Note:  InIn C#C# smallsmall lettersletters areare consideredconsidered differentdifferent thanthan thethe capitalcapital lettersletters (case(case sensitivity)sensitivity)

42 IdentifiersIdentifiers –– ExamplesExamples  ExamplesExamples ofof correctcorrect identifiers:identifiers: int New = 2; // Here N is capital int _2Pac; // This identifiers begins with _ string поздрав = "Hello"; // Unicode symbols used // The following is more appropriate: string greeting = "Hello"; int n = 100; // Undescriptive int numberOfClients = 100; // Descriptive // Overdescriptive identifier: int numberOfPrivateClientOfTheFirm = 100;  ExamplesExamples ofof incorrectincorrect identifiers:identifiers:

int new; // new is a keyword int 2Pac; // Cannot begin with a digit

43 AssigningAssigning ValuesValues ToTo VariablesVariables AssigningAssigning ValuesValues  AssigningAssigning ofof valuesvalues toto variablesvariables  IsIs achievedachieved byby thethe == operatoroperator  TheThe == operatoroperator hashas  VariableVariable identifieridentifier onon thethe leftleft  ValueValue ofof thethe correspondingcorresponding datadata typetype onon thethe rightright  CouldCould bebe usedused inin aa cascadecascade calling,calling, wherewhere assigningassigning isis donedone fromfrom rightright toto leftleft

45 AssigningAssigning ValuesValues –– ExamplesExamples  AssigningAssigning valuesvalues example:example:

int firstValue = 5; int secondValue; int thirdValue;

// Using an already declared variable: secondValue = firstValue;

// The following cascade calling assigns // 3 to firstValue and then firstValue // to thirdValue, so both variables have // the value 3 as a result:

thirdValue = firstValue = 3; // Avoid this!

46 InitializingInitializing VariablesVariables  InitializingInitializing  IsIs assigningassigning ofof initialinitial valuevalue  MustMust bebe donedone beforebefore thethe variablevariable isis used!used!  SeveralSeveral waysways ofof initializing:initializing:  ByBy usingusing thethe newnew keywordkeyword  ByBy usingusing aa literalliteral expressionexpression  ByBy referringreferring toto anan alreadyalready initializedinitialized variablevariable

47 InitializationInitialization –– ExamplesExamples  ExampleExample ofof somesome initializations:initializations:

// The following would assign the default // value of the int type to num: int num = new int(); // num = 0

// This is how we use a literal expression: float heightInMeters = 1.74f;

// Here we use an already initialized variable: string greeting = "Hello World!"; string message = greeting;

48 AssigningAssigning andand InitializingInitializing VariablesVariables

LiveLive DemoDemo LiteralsLiterals WhatWhat areare Literals?Literals?  LiteralsLiterals are:are:  RepresentationsRepresentations ofof valuesvalues inin thethe sourcesource codecode  ThereThere areare sixsix typestypes ofof literalsliterals  BooleanBoolean  IntegerInteger  RealReal  CharacterCharacter  StringString  TheThe nullnull literalliteral 51 BooleanBoolean andand IntegerInteger LiteralsLiterals  TheThe booleanboolean literalsliterals are:are:  truetrue  falsefalse  TheThe integerinteger literals:literals:  AreAre usedused forfor variablesvariables ofof typetype intint,, uintuint,, longlong,, andand ulongulong  ConsistConsist ofof digitsdigits  MayMay havehave aa signsign ((++,,--))  MayMay bebe inin aa hexadecimalhexadecimal formatformat

52 IntegerInteger LiteralsLiterals  ExamplesExamples ofof integerinteger literalsliterals  TheThe ''0x0x'' andand ''0X0X'' prefixesprefixes meanmean aa hexadecimalhexadecimal value,value, e.g.e.g. 0xA8F10xA8F1  TheThe ''uu'' andand ''UU'' suffixessuffixes meanmean aa ulongulong oror uintuint type,type, e.g.e.g. 12345678U12345678U  TheThe ''ll'' andand ''LL'' suffixessuffixes meanmean aa longlong oror ulongulong type,type, e.g.e.g. 9876543L9876543L

53 IntegerInteger LiteralsLiterals –– ExampleExample

// The following variables are // initialized with the same value: int numberInHex = -0x10; int numberInDec = -16;

// The following causes an error, because 234u is of type uint int unsignedInt = 234u;

// The following causes an error, because 234L is of type long int longInt = 234L;  Note:Note: thethe letterletter ‘‘ll’’ isis easilyeasily confusedconfused withwith thethe digitdigit ‘‘11’’ soso it’sit’s betterbetter toto useuse ‘‘LL’!!!’!!!

54 RealReal LiteralsLiterals  TheThe realreal literals:literals:  AreAre usedused forfor valuesvalues ofof typetype floatfloat,, doubledouble andand decimaldecimal  MayMay consistconsist ofof digits,digits, aa signsign andand ““..””  MayMay bebe inin exponentialexponential notation:notation: 6.02e+236.02e+23  TheThe ““ff”” andand ““FF”” suffixessuffixes meanmean floatfloat  TheThe ““dd”” andand ““DD”” suffixessuffixes meanmean doubledouble  TheThe ““mm”” andand ““MM”” suffixessuffixes meanmean decimaldecimal  TheThe defaultdefault interpretationinterpretation isis doubledouble 55 RealReal LiteralsLiterals –– ExampleExample  ExampleExample ofof incorrectincorrect floatfloat literal:literal:

// The following causes an error // because 12.5 is double by default float realNumber = 12.5;  AA correctcorrect wayway toto assignassign floating-pointfloating-point valuevalue (using(using alsoalso thethe exponentialexponential format):format):

// The following is the correct // way of assigning the value: float realNumber = 12.5f; // This is the same value in exponential format: realNumber = 1.25e+7f;

56 CharacterCharacter LiteralsLiterals  TheThe charactercharacter literals:literals:  AreAre usedused forfor valuesvalues ofof thethe charchar typetype  ConsistConsist ofof twotwo singlesingle quotesquotes surroundingsurrounding thethe charactercharacter value:value: ''''  TheThe valuevalue maymay be:be:  SymbolSymbol  TheThe codecode ofof thethe symbolsymbol  EscapingEscaping sequencesequence

57 EscapingEscaping SequencesSequences  EscapingEscaping sequencessequences are:are:  MeansMeans ofof presentingpresenting aa symbolsymbol thatthat isis usuallyusually interpretedinterpreted otherwiseotherwise (like(like ''))  MeansMeans ofof presentingpresenting systemsystem symbolssymbols (like(like thethe newnew lineline symbol)symbol)  CommonCommon escapingescaping sequencessequences are:are:  \'\' forfor singlesingle quotequote \"\" forfor doubledouble quotequote  \\\\ forfor backslashbackslash \n\n forfor newnew lineline  \uXXXX\uXXXX forfor denotingdenoting anyany otherother UnicodeUnicode symbolsymbol

58 CharacterCharacter LiteralsLiterals –– ExampleExample  ExamplesExamples ofof differentdifferent charactercharacter literals:literals:

char symbol = 'a'; // An ordinary symbol symbol = '\u006F'; // Unicode symbol code in // a hexadecimal format symbol = '\u8449'; // 葉 (Leaf in Traditional Chinese) symbol = '\''; // Assigning the single quote symbol symbol = '\\'; // Assigning the backslash symbol symbol = '\n'; // Assigning new line symbol symbol = '\t'; // Assigning TAB symbol symbol = "a"; // Incorrect: use single quotes

59 StringString LiteralsLiterals  StringString literals:literals:  AreAre usedused forfor valuesvalues ofof thethe stringstring typetype  ConsistConsist ofof twotwo doubledouble quotesquotes surroundingsurrounding thethe value:value: """"  MayMay havehave aa @@ prefixprefix whichwhich ignoresignores thethe usedused escapingescaping sequences:sequences: @@""""  TheThe valuevalue isis aa sequencesequence ofof charactercharacter literalsliterals

string s = "I am a sting literal";

60 StringString LiteralsLiterals –– ExampleExample  BenefitsBenefits ofof quotedquoted stringsstrings (the(the @@ prefix):prefix):

// Here is a string literal using escape sequences string quotation = "\"Hello, Jude\", he said."; string path = "C:\\WINNT\\Darts\\Darts.exe";

// Here is an example of the usage of @ quotation = @"""Hello, Jimmy!"", she answered."; path = @"C:\WINNT\Darts\Darts.exe";

string str = @"some text";

 InIn quotedquoted stringsstrings \"\" isis usedused insteadinstead ofof """"!!

61 StringString LiteralsLiterals LiveLive DemoDemo NullableNullable TypesTypes

63 NullableNullable TypesTypes  NullableNullable typestypes areare instancesinstances ofof thethe System.NullableSystem.Nullable structstruct  WrapperWrapper overover thethe primitiveprimitive typestypes  E.g.E.g. int?int?,, double?double?,, etc.etc.  NullabeNullabe typetype cancan representrepresent thethe normalnormal rangerange ofof valuesvalues forfor itsits underlyingunderlying valuevalue type,type, plusplus anan additionaladditional nullnull valuevalue  UsefulUseful whenwhen dealingdealing withwith DatabasesDatabases oror otherother structuresstructures thatthat havehave defaultdefault valuevalue nullnull NullableNullable TypesTypes –– ExampleExample ExampleExample withwith IntegerInteger:: int? someInteger = ; Console.WriteLine( "This is the integer with Null value -> " + someInteger); someInteger = 5; Console.WriteLine( "This is the integer with value 5 -> " + someInteger);

ExampleExample withwith DoubleDouble:: double? someDouble = null; Console.WriteLine( "This is the real number with Null value -> " + someDouble); someDouble = 2.5; Console.WriteLine( "This is the real number with value 5 -> " + someDouble); NullableNullable TypesTypes LiveLive DemoDemo

66 PrimitivePrimitive DataData TypesTypes andand VariablesVariables

Questions?Questions?

http://academy.telerik.com ExercisesExercises

1. DeclareDeclare fivefive variablesvariables choosingchoosing forfor eacheach ofof themthem thethe mostmost appropriateappropriate ofof thethe typestypes bytebyte,, sbytesbyte,, shortshort,, ushortushort,, intint,, uintuint,, longlong,, ulongulong toto representrepresent thethe followingfollowing values:values: 52130,52130, -115,-115, 4825932,4825932, 97,97, -10000.-10000.

2. WhichWhich ofof thethe followingfollowing valuesvalues cancan bebe assignedassigned toto aa variablevariable ofof typetype floatfloat andand whichwhich toto aa variablevariable ofof typetype doubledouble:: 34.567839023,34.567839023, 12.345,12.345, 8923.1234857,8923.1234857, 3456.091?3456.091?

3. WriteWrite aa programprogram thatthat safelysafely comparescompares floating-pointfloating-point numbersnumbers withwith precisionprecision ofof 0.0000010.000001..

68 ExercisesExercises (2)(2)

1. DeclareDeclare anan integerinteger variablevariable andand assignassign itit withwith thethe valuevalue 254254 inin hexadecimalhexadecimal format.format. UseUse WindowsWindows CalculatorCalculator toto findfind itsits hexadecimalhexadecimal representation.representation.

2. DeclareDeclare aa charactercharacter variablevariable andand assignassign itit withwith thethe symbolsymbol thatthat hashas UnicodeUnicode codecode 72.72. Hint:Hint: firstfirst useuse thethe WindowsWindows CalculatorCalculator toto findfind thethe hexadecimalhexadecimal representationrepresentation ofof 72.72.

3. DeclareDeclare aa booleanboolean variablevariable calledcalled isFemaleisFemale andand assignassign anan appropriateappropriate valuevalue correspondingcorresponding toto youryour gender.gender.

69 ExercisesExercises (3)(3)

1. DeclareDeclare twotwo stringstring variablesvariables andand assignassign themthem withwith “Hello”“Hello” andand “World”.“World”. DeclareDeclare anan objectobject variablevariable andand assignassign itit withwith thethe concatenationconcatenation ofof thethe firstfirst twotwo variablesvariables (mind(mind addingadding anan interval).interval). DeclareDeclare aa thirdthird stringstring variablevariable andand initializeinitialize itit withwith thethe valuevalue ofof thethe objectobject variablevariable (you(you shouldshould performperform typetype casting).casting).

2. DeclareDeclare twotwo stringstring variablesvariables andand assignassign themthem withwith followingfollowing value:value:

The "use" of quotations causes difficulties. DoDo thethe aboveabove inin twotwo differentdifferent ways:ways: withwith andand withoutwithout usingusing quotedquoted strings.strings. 70 ExercisesExercises (4)(4)

1. WriteWrite aa programprogram thatthat printsprints anan isoscelesisosceles triangletriangle ofof 99 copyrightcopyright symbolssymbols ©©.. UseUse WindowsWindows CharacterCharacter MapMap toto findfind thethe UnicodeUnicode codecode ofof thethe ©© symbol.symbol.

2. AA marketingmarketing firmfirm wantswants toto keepkeep recordrecord ofof itsits employees.employees. EachEach recordrecord wouldwould havehave thethe followingfollowing characteristicscharacteristics –– firstfirst name,name, familyfamily name,name, age,age, gendergender (m(m oror f),f), IDID number,number, uniqueunique employeeemployee numbernumber (27560000(27560000 toto 27569999).27569999). DeclareDeclare thethe variablesvariables neededneeded toto keepkeep thethe informationinformation forfor aa singlesingle employeeemployee usingusing appropriateappropriate datadata typestypes andand descriptivedescriptive names.names.

3. DeclareDeclare twotwo integerinteger variablesvariables andand assignassign themthem withwith 55 andand 1010 andand afterafter thatthat exchangeexchange theirtheir values.values. 71