Docsity

C Sharp Syntax - C Sharp Programming - Lecture Slides, Slides of C Sharp Programming

Partial preview of the text

Download C Sharp Syntax - C Sharp Programming - Lecture Slides and more Slides C Sharp Programming in PDF only on Docsity!

The C# Language and

Program Structure

Lecture Overview (1)

 Basics of the C# language for the VB programmer  Language syntax  The basics of data types  Numeric types  Integral types  Floating point types  String types

THE BIG DIFFERENCE

C# IS CASE

SENSITIVE

C# Syntax

 All words are categorized as  Identifiers (programmer chosen names)  Keywords (words reserved by the C# language)  You can force a keyword to operate as a variable using the @ character  Literals (numbers or strings you embed into the application)

Statements

 In C#, all statements end with a semicolon ;  Statements can span multiple lines  There is no need for a continuation character as in VB  Example C# System.Console.WriteLine( “This is a line of text”);  Example VB System.Console.WriteLine( _ “This is a line of text”);

C# Blocks

 In VB, blocks are marked with keywords  Sub – End SubIf – End IfDo LoopWhile End While  In C#, blocks are all marked with {} as in Java or C++

Comments

 XMLSummary comments begin with ///  Single line comments are marked with //  Multi-line comments start with /* and end with */

// A comment.

/ This is Also a comment /

Introduction to Types

 A type is a blueprint for a value

 That blueprint defines the range of allowable values and other information  Types are predefined by the C# language  Custom types you create work the same way

 We call this type symmetry

Custom Types

 Complex types are created from primitive types and other complex types  These types contain  Data members  Function members  A special function member called a constructor

Types of Types

 All types fall into one of the following two categories  Value types comprise most built-in types  enum and struct are also value types  Arrays and classes are reference types  Along with just about everything else

Reference Types

 There are two parts to a reference type  An object  A reference to the object  See figure 2-3 on page 18

Null – the Special Case

 A special case when a reference type variable DOES NOT point to an object  Here is where null reference exceptions come from

Variable Declarations

 Variable declarations work the same way in both C# and VB  Local variables are declared inside of a procedure  Module-level variables are declared outside of a procedure  In C#, the declaration syntax is reversed from VB

Local Variable Declaration

(Examples)

 VB

Dim count As Integer Dim MyName As String = “Ekedahl”

 C#

int count; string MyName = “Ekedahl”;