1 session 01 module 1: introduction to c# module 2: variables and data types
TRANSCRIPT
![Page 1: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/1.jpg)
1
Session 01
Module 1: Introduction to C#
Module 2: Variables and Data Types
![Page 2: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/2.jpg)
Introduction & Variables & Data types / Session 1 / 2 of 41
Module1 - Objectives
Describe the .NET Framework List the other components of .NET Framework Explain CLR and MSIL Define Memory Management and Garbage
Collection Describe the Microsoft Visual Studio 2005 product Learn the key elements of Visual Studio 2005
IDE List the basic features of C#
![Page 3: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/3.jpg)
Introduction & Variables & Data types / Session 1 / 3 of 41
Architecture of .Net Framework(1)
The .Net Framework is a multi-lingual environment to build, deploy and run applications
It enables programmers to develop applications for various platform such as mobile devices, desktop computer, smartphones and so on.
![Page 4: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/4.jpg)
Introduction & Variables & Data types / Session 1 / 4 of 41
Architecture of .Net Framework(2)
The .Net Framework architecture comprises of following: Languages included in the .Net Framework .Net Framework class library (FCL) The Common Language Runtime(CLR)
![Page 5: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/5.jpg)
Introduction & Variables & Data types / Session 1 / 5 of 41
Architecture of .Net Framework(3) Other importance components in .Net Framework
Web Forms Web services Windows Forms ASP.NET ADO.NET XML Classes Base Framework Classes Common Language Specification Common Type System
![Page 6: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/6.jpg)
Introduction & Variables & Data types / Session 1 / 6 of 41
Microsoft Intermediate Language(MSIL)
When code written in .Net Framework language such as C#,VB…is complied, output code is in the form of Microsoft Intermediate Language(MSIL)
![Page 7: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/7.jpg)
Introduction & Variables & Data types / Session 1 / 7 of 41
Common Language Runtime(CLR)
When a code is executed for first time, the MSIL code is converted to a code native to operating system.
This is done ar runtime by the Just-in-Time(JIT) compiler present in CLR.
![Page 8: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/8.jpg)
Introduction & Variables & Data types / Session 1 / 8 of 41
Basic Features of C#
Object-oriented programming language Type safety checking Garbage collection Standarbisation by ECMA(European
Computer Manufacturers Association) Generic Types and Methods
![Page 9: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/9.jpg)
Introduction & Variables & Data types / Session 1 / 9 of 41
Visual Studio 2005(1)
Visual studio 2005 is complete set of development tools to build desktop applications, web application, XML web service and mobile applications.
Primary advantages are: Development of applications for .Net Framework
2.0 Development of applications for handheld devices
using .Net Compact Framework 2.0
![Page 10: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/10.jpg)
Introduction & Variables & Data types / Session 1 / 10 of 41
Visual Studio 2005(2)
![Page 11: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/11.jpg)
Introduction & Variables & Data types / Session 1 / 11 of 41
Key elements of VS 2005
Solution Explorer Code Editor Properties Window Dynamic help
![Page 12: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/12.jpg)
Introduction & Variables & Data types / Session 1 / 12 of 41
Write and run first console application
Step 1: Create new project
![Page 13: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/13.jpg)
Introduction & Variables & Data types / Session 1 / 13 of 41
Write and run first console application Step 2:Compile program
You can compile console application from command line or use IDE
If compile program from command line:
Edit PATH variable, add following line in PATHC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;
in command line window, change to directory of program and type: csc <fileName.cs>
If use IDE, press F6 to compile program
![Page 14: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/14.jpg)
Introduction & Variables & Data types / Session 1 / 14 of 41
Write and run first console application
Step 3: Run program If use command line window, type .exe file name If use IDE, press Ctrl + F5
![Page 15: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/15.jpg)
Introduction & Variables & Data types / Session 1 / 15 of 41
Module 1 – Summary (1)
.Net Framework is multi-language platform to build, deploy and run various types of applications
Two major components of .Net Framework is CLR and FCL
When code is written in .Net language such as C#,VB…compiled, output code is converted to code native to operating system by Just-In-Time language
![Page 16: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/16.jpg)
Introduction & Variables & Data types / Session 1 / 16 of 41
Module 1 – Summary (2)
C# is an object-oriented programming language derived from c and C++.
C# support features like type-safety checking, garbage collection, ECMA standardization, generics
Visual studio 2005 is complete set of tool to build high performance applications
![Page 17: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/17.jpg)
Introduction & Variables & Data types / Session 1 / 17 of 41
Module 2 - Objectives
Identify basic data types in C# Explain XML source code documentation List the keywords in C# Describe reference data types Constants and Literals Describe console output methods in C# Explain number and datetime format
specifiers
![Page 18: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/18.jpg)
Introduction & Variables & Data types / Session 1 / 18 of 41
Variables
A variable is an entity whose value can keep changing
Declaration syntax:<datatype> <variableName> [,variableName=<value>];
Assignment syntax: <variable> = <value>;
![Page 19: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/19.jpg)
Introduction & Variables & Data types / Session 1 / 19 of 41
Data Types (1)
In C#, data types are also divided into two categories: Value types:
Can be either the built-in data type or a user-defined data type.
Stack storage results in faster memory allocation to variables of value types
Reference types: Variables of reference type store the memory address
of other variables in a heap. Most of user-defined data types such as class are
reference types.
![Page 20: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/20.jpg)
Introduction & Variables & Data types / Session 1 / 20 of 41
Data Types (2)
![Page 21: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/21.jpg)
Introduction & Variables & Data types / Session 1 / 21 of 41
Predefined Data Types (1)
The predefined data types are referred to as basic data types in C#.
These data types have a predefined range and size.
The size of the data type helps the compiler to allocate memory space and ensure the value assigned is within the range of the data type.
![Page 22: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/22.jpg)
Introduction & Variables & Data types / Session 1 / 22 of 41
Predefined Data Types (2)
![Page 23: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/23.jpg)
Introduction & Variables & Data types / Session 1 / 23 of 41
Reference Data Type Classification
Reference types can be classified as
![Page 24: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/24.jpg)
Introduction & Variables & Data types / Session 1 / 24 of 41
Some Reference Data Types
![Page 25: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/25.jpg)
Introduction & Variables & Data types / Session 1 / 25 of 41
Variable Naming Rules
![Page 26: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/26.jpg)
Introduction & Variables & Data types / Session 1 / 26 of 41
Comments
Comments are given by programmer to provide information about a piece of code.
Comments make the program more readable. Comments help the programmer to explain the purpose
of using a particular variable, method, class, or code snippet.
Comments are ignored by the compiler during the execution of the program.
C# supports three types of comments: Single-line comments Multiple-line comments XML comments
![Page 27: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/27.jpg)
Introduction & Variables & Data types / Session 1 / 27 of 41
XML Documentation
In C#, we can create an XML document that will contain all the XML comments.
This document is useful when multiple programmers want to view information of the program.
To create an XML document, we must use the VS 2005 command prompt window.
csc /doc:<XMLfilename.xml> <CSharpfilename.cs>
![Page 28: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/28.jpg)
Introduction & Variables & Data types / Session 1 / 28 of 41
Predefined XML Tags
XML comments are inserted in XML tags. These tags can either be predefined or user-defined.
XML comments begin with three forward slashes (///)
![Page 29: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/29.jpg)
Introduction & Variables & Data types / Session 1 / 29 of 41
Constants
Constants are fixed values assigned to identifiers that are not modified throughout the execution of the code.
We have to initialize a constant at the time of its declaration.
The compiler can identify constants at the time of compilation because of the const keyword.
![Page 30: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/30.jpg)
Introduction & Variables & Data types / Session 1 / 30 of 41
Literals
A literal is a static value assigned to variables and constants
In C#, there are six types of literals
![Page 31: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/31.jpg)
Introduction & Variables & Data types / Session 1 / 31 of 41
Keywords
Keywords are reserved words and are separately compiled by the compiler.
They convey a predefined meaning to the compiler and hence cannot be created or modified.
![Page 32: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/32.jpg)
Introduction & Variables & Data types / Session 1 / 32 of 41
Escape sequence characters in C#
![Page 33: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/33.jpg)
Introduction & Variables & Data types / Session 1 / 33 of 41
Console Input/Output Operations
Two output methods: Console.Write() and Console.WriteLine()
These two methods accept parameters for formatting the text before the output is displayed Console.Write(“Customer name: {0}”, custName); Console.WriteLine(“Total amount: ${0:#,###.#0}”, totalAmount);
Two input methods: Console.Read() and Console.ReadLine() custName = Console.ReadLine();
![Page 34: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/34.jpg)
Introduction & Variables & Data types / Session 1 / 34 of 41
Convert Methods
The ReadLine() method can also be used to accept integer values.
The data is accepted as string and then converted into other data type by a Convert class age = Convert.ToInt32(Console.ReadLine());
![Page 35: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/35.jpg)
Introduction & Variables & Data types / Session 1 / 35 of 41
Format Specifiers
Format specifiers are special characters that are used to display values of variables in a formatted manner.
Some type of format specifiers Number Format Specifiers Datetime Format Specifiers
![Page 36: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/36.jpg)
Introduction & Variables & Data types / Session 1 / 36 of 41
Number Format Specifiers
We can convert numeric values in different formats.
![Page 37: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/37.jpg)
Introduction & Variables & Data types / Session 1 / 37 of 41
More Number Format Specifiers
![Page 38: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/38.jpg)
Introduction & Variables & Data types / Session 1 / 38 of 41
Datetime Format Specifiers
![Page 39: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/39.jpg)
Introduction & Variables & Data types / Session 1 / 39 of 41
More Datetime Format Specifiers
![Page 40: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/40.jpg)
Introduction & Variables & Data types / Session 1 / 40 of 41
Module 2 – Summary (1)
In C#, data types are also divided into two categories: value types and reference types
The predefined data types are referred to as basic data types in C#.
C# supports three types of comments XML comments are inserted in XML tags.
These tags can either be predefined or user-defined.
![Page 41: 1 Session 01 Module 1: Introduction to C# Module 2: Variables and Data Types](https://reader036.vdocuments.us/reader036/viewer/2022062516/56649e375503460f94b2710e/html5/thumbnails/41.jpg)
Introduction & Variables & Data types / Session 1 / 41 of 41
Module 2 – Summary (2)
Two output methods: Console.Write() and Console.WriteLine()
Two input methods: Console.Read() and Console.ReadLine()
Convert class is used to convert a variable into another data type.
Some type of format specifiers: number and datatime