Top Banner
C#: INTRODUCTION FOR DEVELOPERS Neal Stublen [email protected]
46

C#: Introduction for Developers

Feb 15, 2016

Download

Documents

dora

Neal Stublen [email protected]. C#: Introduction for Developers. Overview of .NET. Windows Applications. Windows Application . Microsoft Windows OS / Intel Platform. Display. File System. Network. .NET Applications. .NET Application (or "Assembly"). .NET Framework. Class Libraries. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: C#: Introduction for Developers

C#: INTRODUCTION

FOR DEVELOPERS

Neal [email protected]

Page 2: C#: Introduction for Developers

Overview of .NET

Page 3: C#: Introduction for Developers

Windows Applications

Microsoft Windows OS / Intel Platform

Windows Application

File System NetworkDisplay

Page 4: C#: Introduction for Developers

.NET Applications

.NET Framework

Class Libraries

Common Language Runtime (CLR)

.NET Application (or "Assembly")

Non-Microsoft OS? / Non-Intel Platform?Microsoft Windows OS / Intel Platform

File System NetworkDisplay

Page 5: C#: Introduction for Developers

C#, .NET, and Windows

C# Source Files

.NET "Assembly"

(MSIL)

C# Compiler

.NET "Assembly"

(MSIL)

CLR

"Native" Code

Page 6: C#: Introduction for Developers

How does C# compare? VB.NET, F#, Managed VC++ are

other .NET languages.  They all compile into MSIL assemblies that run on the .NET CLR.

Java has many similarities, but the .NET class library is different from the Java support classes.

Might be considered a "safer" version of C++.

Page 7: C#: Introduction for Developers

Using Visual Studio

Page 8: C#: Introduction for Developers

Visual Studio Summary Open/close a project/solution Project

A collection of files that are used to generate an application or class library

.csproj file extention Solution

A collection of projects.sln file extension

Projects target a specific version of the .NET Framework

Page 9: C#: Introduction for Developers

Visual Studio Summary Menus and toolbars can be customized Solution Explorer manages project files Form Designer allows us to create and

modify forms Controls are added to a form using the

Toolbox Properties change the appearance

and/or function of a form or control

Page 10: C#: Introduction for Developers

Visual Studio Summary Tabbed windows can be docked just about

anywhere Tabbed windows can be floating or docked Tabbed windows can be pinned or hidden

Code Editor allows you to edit source code Editing window can be split into two panes

Page 11: C#: Introduction for Developers

Visual Studio Summary Settings can be imported and exported We will work with WinForms applications

in this class.

Page 12: C#: Introduction for Developers

Designing a Form

Page 13: C#: Introduction for Developers

Form Design Summary Control Toolbox Tab Order Properties Window

Name, TextEnabled, ReadOnly, TabOrder, TabStop, TextAlignAcceptButton, CancelButton, StartPosition

Access keys (&) Document Outline View Renaming and saving files

Page 14: C#: Introduction for Developers

Form Exercise Create a project named "InvoiceTotal" in

your S: folder Reproduce the following form:

Consider tab order, access keys, etc.

Page 15: C#: Introduction for Developers

Object Oriented Programming

Page 16: C#: Introduction for Developers

Object-Oriented Programming .NET represents everything as an "object" What objects can we identify in our

InvoiceTotal application?Forms, Controls

Objects are made up of data and a set of functions that act on that data

What data would be stored in the InvoiceTotal form and controls?Position, Text

What functions might use that data?

Page 17: C#: Introduction for Developers

Objects and Classes An object is represented by a "class" A class has “member” data

Variables A class has “member” functions

Methods

Page 18: C#: Introduction for Developers

A class Definitionclass Counter{   

};

Page 19: C#: Introduction for Developers

A class Definitionclass Counter{       // “class” is a keyword that tells the // compiler we are defining a new type of        // object.

                                 };

Page 20: C#: Introduction for Developers

The class Name (or Type)

class Counter{       // “Counter” is the name of the new class // type.

   

                      };

Page 21: C#: Introduction for Developers

Member Variablesclass Counter{    private int mValue;

    // We declare member variables that will // hold data for the class.

};

Page 22: C#: Introduction for Developers

Member Visibilityclass Counter{    private int mValue;

    // “private” is a keyword that tells the // compiler the class member is not visible // to other objects.   

                  };

Page 23: C#: Introduction for Developers

Member Typeclass Counter{    private int mValue;

    // “int” is a built-in type that tells the // compiler we are defining an integer // value.          

                      };

Page 24: C#: Introduction for Developers

Member Nameclass Counter{    private int mValue;

    // “mValue” is the name we will use when // referring to this data member.

          

                      };

Page 25: C#: Introduction for Developers

Member Initializerclass Counter{    private int mValue = 0;

    // (Optional) We can assign an initial value to // the data member.

          

                      };

Page 26: C#: Introduction for Developers

A class Constructorclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

                      };

Page 27: C#: Introduction for Developers

Constructor Visibilityclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // “public” is a keyword that tells the // compiler the class member is visible to // other objects.

};

Page 28: C#: Introduction for Developers

Constructor Nameclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // “Counter” repeats the class name, which // tells the compiler we are defining a // constructor for the class.           };

Page 29: C#: Introduction for Developers

Constructor Parameterclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // “int inInitialValue” is a parameter of // the constructor. It is used to set the // initial state of the object.

};

Page 30: C#: Introduction for Developers

Constructor Bodyclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // The body of the constructor assigns // initial values to any data members of // the class.

};

Page 31: C#: Introduction for Developers

Assignment Operatorclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // “=” is an assignment operator that assigns // a value to a variable.

};

Page 32: C#: Introduction for Developers

A class Methodclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // Increment the counter by one.    public int Increment()    {        return ++mValue;    }};

Page 33: C#: Introduction for Developers

Method Visibilityclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // Increment the counter by one.    public int Increment()    {        return ++mValue;    }};

Page 34: C#: Introduction for Developers

Method Return Typeclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // Increment the counter by one.    public int Increment()    {        return ++mValue;    }};

Page 35: C#: Introduction for Developers

Method Nameclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // Increment the counter by one.    public int Increment()    {        return ++mValue;    }};

Page 36: C#: Introduction for Developers

Method Bodyclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // Increment the counter by one.    public int Increment()    {        return ++mValue;    }};

Page 37: C#: Introduction for Developers

Prefix/Postfix Operatorsclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // Increment the counter by one.    public int Increment()    {        return ++mValue;    }};

Page 38: C#: Introduction for Developers

Code Commentsclass Counter{    private int mValue;

    // Constructor    public Counter(int inInitialValue)    {        mValue = inInitialValue;    }

    // Increment the counter by one.    public void Increment()    {        mValue = mValue + 1;    }};

Counter myCounter = new Counter(0);

Page 39: C#: Introduction for Developers

Instantiating a classclass Counter{ ...};

Counter myCounter = new Counter(0);Counter yourCounter = new Counter(10);

Page 40: C#: Introduction for Developers

Instantiating a classclass Counter{ ...};

Counter myCounter = new Counter(0);Counter yourCounter = new Counter(10);

// “new” is a keyword that tells the compiler// we want to create an instance of the class.

// We have created two instances of the Counter// class.

Page 41: C#: Introduction for Developers

Instantiating a classclass Counter{ ...};

Counter myCounter = new Counter(0);myCounter.Increment();

// We call a method by using the “.” operator on// a class instance.

// All statements are terminated by a semi-colon.

Page 42: C#: Introduction for Developers

A Closer Look at Our Form

Page 43: C#: Introduction for Developers

Form Summary The Code Editor allows us to expand

and collapse blocks of code. Forms are just objects Forms are created by making changes

to the object’s properties and calling the object’s methods.

The Designer just adds code to the form’s class.

Page 44: C#: Introduction for Developers

Making the FormDo Something

Page 45: C#: Introduction for Developers

Event Summary Forms and controls dispatch events Event handlers respond to events

Page 46: C#: Introduction for Developers

Suggestions Install Visual Studio

Visual Studio Express 2013 for Windows Desktop

Projects at end of each chapter Experiment