21
Introduction to the C# Programming Language for the VB Programmer

Introduction to the C# Programming Language for the VB Programmer

  • Upload
    ansel

  • View
    38

  • Download
    2

Embed Size (px)

DESCRIPTION

Introduction to the C# Programming Language for the VB Programmer. Lecture Overview. Compilation and execution of programs Some key terms Introduce the C# programming language for the VB developer Mention some important features of the Visual Studio .NET environment - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to the  C# Programming Language for the VB Programmer

Introduction to the C# Programming

Language for the VB Programmer

Page 2: Introduction to the  C# Programming Language for the VB Programmer

Slide 2

Lecture Overview Compilation and execution of programs

Some key terms Introduce the C# programming

language for the VB developer Mention some important features of the

Visual Studio .NET environment Pass along some editing tips and tricks

Page 3: Introduction to the  C# Programming Language for the VB Programmer

Slide 3

Program Compilation The .NET languages are compiled

languages Code is compiled from the source

language (VB, C#, etc..) into machine independent assembly language (MSIL) MSIL is converted to executable through

JITing (Just in time)

Page 4: Introduction to the  C# Programming Language for the VB Programmer

Slide 4

Program Execution (1) .NET applications use the Common

Language Runtime (CLR) and are executed as Managed Code

Libraries are stored in framework classes

Your code and framework classes are executed by the CLR

Page 5: Introduction to the  C# Programming Language for the VB Programmer

Slide 5

Program Execution (2)

Page 6: Introduction to the  C# Programming Language for the VB Programmer

Slide 6

Fundamentals of .NET and C# (1) Unified type system (Common Type

System) Unified run-time engine with memory

management built-in (Common Language Runtime) (Garbage collection)

It’s a type safe language Static types are enforced at compile time

rather than at run time

Page 7: Introduction to the  C# Programming Language for the VB Programmer

Slide 7

Fundamentals of .NET and C# (2) Classes encapsulate functionality and

have methods, properties (object orientation)

Classes implement interfaces See Figure 1.1

Page 8: Introduction to the  C# Programming Language for the VB Programmer

Slide 8

C# Development and Runtime Model

Page 9: Introduction to the  C# Programming Language for the VB Programmer

Slide 9

Assemblies and Namespaces Assemblies are physical – Namespaces are

logical An assembly may contain one or more

namespaces The .NET Framework is just a bunch of assemblies

Namespaces are organized into a hierarchy Namespaces are connected together with a dot (.) System namespace contains components

developed by the .NET team Microsoft namespace contains components

developed by Microsoft but outside of the .NET development team

We references these assemblies and namespaces from our applications

Page 10: Introduction to the  C# Programming Language for the VB Programmer

Slide 10

Common Assemblies System.dll defines the primary data types System.Data.dll defines the components

that make up ADO.NET System.Drawing.dll contains the

components used to draw various shapes to an output device

Forms and printers are output devices System.Windows.Forms.dll contains

components to implement desktop forms System.XML.dll used to process XML

documents

Page 11: Introduction to the  C# Programming Language for the VB Programmer

Slide 11

Common Namespaces System namespace contains fundamental

classes System.Data namespace contains classes

supplying data access capabilities ADO.NET

System.Drawing provides access to the Graphical Device Interface allowing shapes to be drawn to forms and printers

System.IO provides access to files System.Windows.Forms supplies the

capabilities to create forms and control instances on those forms

Page 12: Introduction to the  C# Programming Language for the VB Programmer

Slide 12

Adding an Assembly Reference

Page 13: Introduction to the  C# Programming Language for the VB Programmer

Slide 13

Importing and Using Namespaces By default, you must fully qualify class

and method names System.IO.StreamReader for example

In VB, the Imports statement allows unqualified references Imports System.IO

In C#, it’s the using statement using System.IO;

Page 14: Introduction to the  C# Programming Language for the VB Programmer

Slide 14

Project Structure Everything is the same as VB

Solution file, project file, program files Namespace references

Modules have a file suffix of .cs instead of .vb

Application startup works a bit differently VB uses a form or Sub Main C# has a “special” procedure named

Main()

Page 15: Introduction to the  C# Programming Language for the VB Programmer

Slide 15

Solution Explorer Shows all relevant project files

Page 16: Introduction to the  C# Programming Language for the VB Programmer

Slide 16

And now for the all Famous Hello World Create a new C# Console project

Page 17: Introduction to the  C# Programming Language for the VB Programmer

Slide 17

Program.cs using statements replace Imports

statement

Page 18: Introduction to the  C# Programming Language for the VB Programmer

Slide 18

Program.cs namespace forms the outer block { } marks a block

Page 19: Introduction to the  C# Programming Language for the VB Programmer

Slide 19

Program.cs namespace blocks contain classes,

which contain properties and methods

Page 20: Introduction to the  C# Programming Language for the VB Programmer

Slide 20

Program.cs The Main() method is called the entry

point It’s where program execution begins

Must be declared as static Method can return either a void or an int

Page 21: Introduction to the  C# Programming Language for the VB Programmer

Slide 21

Program.cs Methods (Main) contain local variable

declarations and executable statements