week 1 introducing-c

Upload: vipnat

Post on 08-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 Week 1 Introducing-c

    1/15

    4/18/20

    Week 1: THE C# LANGUAGE

    Chapter 1: Variables and Expressions

    What the .NET Framework is and what it contains

    How .NET applications work

    What C# is and how it relates to the .NET Framework

    What tools are available for creating .NET applications

    with C#

    WHAT IS THE .NET FRAMEWORK?

    Microsofts modern software developmentplatform

    Supports several programming languages,

    including C#, Visual Basic, C++, F#

    Programs executed by Common LanguageRuntime (CLR)

    Includes a large library of components

    (classes) which can be used in programs

    Win do ws Pro gra mm in g 1 C ha pt er 1 : I nt ro du ci ng C# S li de 2

    Writing Applications Using the .NET

    Framework

    CIL (Common Intermediate Language code.),

    JIT (just-in-time compiler)

    MSIL or IL (Microsoft Intermediate Language)

    Assemblies Managed Code

    Garbage Collection

    Win do ws Pro gra mm in g 1 C ha pt er 1 : I nt ro du ci ng C# S li de 3

  • 8/7/2019 Week 1 Introducing-c

    2/15

    4/18/20

    Writing Applications Using the .NET

    Framework

    Win do ws Pro gra mm in g 1 C ha pt er 1 : I nt ro du ci ng C# S li de 4

    WHAT IS C#?

    Applications You Can Write with C#

    Windows applications

    Web applications:

    Web services:

    Win do ws Pro gra mm in g 1 C ha pt er 1 : I nt ro du ci ng C# S li de 5

    Visual Studio

    Powerful, professional IntegratedDevelopment Environment (IDE)

    Integrates compilers, debugger and many

    other useful tools for development Can work with many different types of project,

    including:

    Console (text-based) applications

    Windows (GUI) applications

    Web applications (ASP.NET)

    Class libraries

    Win do ws Pro gra mm in g 1 C ha pt er 1 : I nt ro du ci ng C# S li de 6

  • 8/7/2019 Week 1 Introducing-c

    3/15

    4/18/20

    Visual Studio

    Solution explorer

    Toolbox windows

    Visual designer

    Properties windows

    Win do ws Pro gra mm in g 1 C ha pt er 1 : I nt ro du ci ng C# S li de 7

    Visual Studio projects

    A project contains source code files, settingsand resources for an application

    May contain references to class libraries

    May contain data used by application

    Building a project:

    Compiles source files

    Copies non-source files to output folder

    Creates an assembly in output folder

    Building a solution builds all its projects

    Win do ws Pro gra mm in g 1 C ha pt er 1 : I nt ro du ci ng C# S li de 8

    Project details

    References class librariesused by this application

    Solution folder contents

    Project folder contents

    Solution file (.sln) and project file

    (.csproj) are created by VS and

    contain solution/project

    configuration information

    Win do ws Pro gra mm in g 1 C ha pt er 1 : I nt ro du ci ng C# S li de 9

  • 8/7/2019 Week 1 Introducing-c

    4/15

    4/18/20

    Creating a Visual Studio project

    Demo

    Win do ws Pro gra mm in g 1 C ha pt er 1: In tro du ci ng C# S li de 10

    SUMMARY

    Win do ws Pro gra mm in g 1 C ha pt er 1: In tro du ci ng C# S li de 11

    Week 1: THE C# LANGUAGE

    Chapter 2: Writing a C#Program

    A basic working knowledge of Visual Studio

    2010 and Visual C# 2010 Express Edition

    How to write a simple console application

    How to write a Windows Forms application

  • 8/7/2019 Week 1 Introducing-c

    5/15

    4/18/20

    Visual C# 2010 Ultimate

    Windows Programming 1 Chapter 2: Writing a C# Program Slide 13

    CONSOLE APPLICATIONS

    Windows Programming 1 Chapter 2: Writing a C# Program Slide 14

    WINDOWS FORMS APPLICATIONS

    Windows Programming 1 Chapter 2: Writing a C# Program Slide 15

  • 8/7/2019 Week 1 Introducing-c

    6/15

    4/18/20

    The Solution Explorer

    W indows Progr amming 1 C ha pter 1 : Introducing C # S lide 1 6

    The Properties Window

    W indows Progr amming 1 C ha pter 1 : Introducing C # S lide 1 7

    Code view

    W indows Progr amming 1 C ha pter 1 : Introducing C # S lide 1 8

  • 8/7/2019 Week 1 Introducing-c

    7/15

    4/18/20

    The Error List Window

    W indows Progr amming 1 C ha pter 1 : Introducing C # S lide 1 9

    SUMMARY

    Windows Programming 1 Chapter 2: Writing a C# Program Slide 20

    Week 1: THE C# LANGUAGE

    Chapter 3:Variables and Expressions

    Basic C# syntax

    Variables and how to use them

    Expressions and how to use them

  • 8/7/2019 Week 1 Introducing-c

    8/15

    4/18/20

    BASIC C# SYNTAX

    The look and feel of C# code is similar to thatof C++ and Java.

    C# compilers ignore additional spacing in

    code, whether it results from spaces, carriagereturns, or tab characters (collectively known

    as whitespace characters).

    Statements

    C# is a block-structured language, meaning

    statements are part of a blockof code.

    Windows Programming 1 Chapter3: Variables and Expressions Slide 22

    block

    These blocks, which are delimited with curlybrackets ({ and }), may contain any number of

    statements, or none at all

    Windows Programming 1 Chapter3: Variables and Expressions Slide 23

    comments

    Comments can be created using //

    Multi-lines comments use /* */

    You can use single-line comments that

    start with three / symbols instead of two/// A special comment

    Comments are ignored by the compiler

    Used only for human readers

    Windows Programming 1 Chapter3: Variables and Expressions Slide 24

  • 8/7/2019 Week 1 Introducing-c

    9/15

    4/18/20

    The code outlining

    You can do this with the #region and#endregion keywords, which define the start

    and end of a region of code that can be

    expanded and collapsed.

    Windows Programming 1 Chapter3: Variables and Expressions Slide 25

    VARIABLES

    C# syntax for declaring variables merelyspecifies the type and variable name:

    ;

    int intNumberOfStudents;

    Declaration includes

    Name, follow Naming Convention Rules

    Data Type

    Required Value for Constants

    Optional Initial Value for Variables

    Windows Programming 1 Chapter3: Variables and Expressions Slide 26

    Simple Types

    Windows Programming 1 Chapter3: Variables and Expressions Slide 27

  • 8/7/2019 Week 1 Introducing-c

    10/15

    4/18/20

    Simple Types

    Windows Programming 1 Chapter3: Variables and Expressions Slide 28

    Simple Types

    Windows Programming 1 Chapter3: Variables and Expressions Slide 29

    Using Simple Type Variables

    Windows Programming 1 Chapter3: Variables and Expressions Slide 30

  • 8/7/2019 Week 1 Introducing-c

    11/15

    4/18/20

    Variable Naming

    The first character of a variable name must beeither a letter, an underscore character (_),

    or the atsymbol (@).

    Subsequent characters may be letters,underscore characters, or numbers.

    Windows Programming 1 Chapter3: Variables and Expressions Slide 31

    String Literals

    Windows Programming 1 Chapter3: Variables and Expressions Slide 32

    String Literals

    This means that the following strings areequivalent:

    "Karli \s string."

    "Karli \u0027 s string. @ "A short list:

    item 1

    item 2

    "C:\\Temp\\MyDir\\MyFile.doc

    @ "C:\Temp\MyDir\MyFile.doc"

    Windows Programming 1 Chapter3: Variables and Expressions Slide 33

  • 8/7/2019 Week 1 Introducing-c

    12/15

    4/18/20

    EXPRESSIONS

    Operators can be roughly classified into threecategories:

    Unary Act on single operands

    BinaryAct on two operands

    TernaryAct on three operands

    Windows Programming 1 Chapter3: Variables and Expressions Slide 34

    Mathematical Operators

    Windows Programming 1 Chapter3: Variables and Expressions Slide 35

    Windows Programming 1 Chapter3: Variables and Expressions Slide 36

  • 8/7/2019 Week 1 Introducing-c

    13/15

    4/18/20

    Manipulating Variables with

    Mathematical Operators

    Windows Programming 1 Chapter3: Variables and Expressions Slide 37

    Assignment Operators

    Windows Programming 1 Chapter3: Variables and Expressions Slide 38

    Operator Precedence

    Windows Programming 1 Chapter3: Variables and Expressions Slide 39

  • 8/7/2019 Week 1 Introducing-c

    14/15

    4/18/20

    Namespaces

    Namespaces are also used as a means ofcategorizing items in the .NET Framework

    C# code, by default, is contained in the global

    namespace

    Qualified names use period characters (.)between namespace levels

    System.Int32

    Windows Programming 1 Chapter3: Variables and Expressions Slide 40

    Namespaces

    Windows Programming 1 Chapter3: Variables and Expressions Slide 41

    Code in the global namespace, however, must

    refer to this name using the classified name

    LevelOne.NameOne.

    Namespaces

    Within a namespace, you can define nested

    namespaces, also using the namespace keyword.

    Windows Programming 1 Chapter3: Variables and Expressions Slide 42

  • 8/7/2019 Week 1 Introducing-c

    15/15

    4/18/20

    SUMMARY

    Windows Programming 1 Chapter 3: Variables and Expressions Slide 43