are all structs user defined primitive types complex

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: le, color, rational Multiple interface inheritance Same members as class Member access public, internal, private Instantiated with new operator Types Classes and Structs struct SPoint { int x, y; ... } class CPoint { int x, y; ... } SPoint sp = new SPoint(10, 20); CPoint cp = new CPoint(10, 20); sp 10 20 cp CPoint 10 20 Types Delegates A delegate is a reference type that defines a method signature When instantiated, a delegate holds one or more methods Essentially an object-oriented function pointer Foundation for framework events Outline Hello World Design Goals of C# Types Program Structure Statements Operators Using Visual Studio Using the .NET Framework SDK Program Structure Overview Organizing Types Namespaces References Main Method Syntax Program Structure Organizing Types Types are defined in files A file can contain multiple types Files are compiled into assemblies assembly is a DLL or EXE Program Structure Namespaces Namespaces provide a way to uniquely identify a type Provides logical organization of types Namespaces can span assemblies Can nest namespaces There is no relationship between namespaces and file structure (unlike Java) The fully qualified name of a type includes all namespaces Program Structure Namespaces namespace N1 { class C1 { class C2 { } } namespace N2 { class C2 { } } } // N1 // N1.C1 // N1.C1.C2 // N1.N2 // N1.N2.C2 Program Structure Namespaces The using statement lets you use types without typing the fully qualified name Can always use a fully qualified name using N1; C1 a; N1.C1 b; // The N1. is implicit // Fully qualified name C2 c; N1.N2.C2 d; C1.C2 e; // Error! C2 is undefined // One of the C2 classes // The other one Program Structure Namespaces The using statement also lets you create aliases using C1 = N1.N2.C1; using N2 = N1.N2; C1 a; N2.C1 b; // Refers to N1.N2.C1 // Refers to N1.N2.C1 Program Structure Namespaces Best practice: Put all of your types in a unique namespace Have a namespace for your company, project, product, etc. Look at how the .NET Framework classes are organized Program Structure References In Visual Studio you specify references for a project Each reference identifies a specific assembly Passed as reference (/r or /reference) to the C# compiler csc HelloWorld.cs /reference:System.WinForms.dll Program Structure Namespaces vs. References Namespaces provide language-level naming shortcuts Don’t have to type a long fully qualified name over and over References specify which assembly to use Program Structure Main Method Execution begins at the static Main() method Can have only one method with one of the following signatures in an assembly static static static static void Main() int Main() void Main(string args) int Main(string args) Outline Hello World Design Goals of C# Types Program Structure Statements Operators Using Visual Studio Using the .NET Framework SDK Statements Overview High C++ fidelity if, while, do require bool condition goto can’t jump into blocks switch statement No fall-through foreach statement checked and unchecked statements Expression void Foo() { i == 1; statements } must do work // error Statements Overview Statement lists Block statements Labeled statements Declarations Constants Variables Expression statements checked, unchecked lock using Conditionals if switch Loop Statements while do for foreach Jump Statements break continue goto return throw Exception handling try throw Statements Syntax Statements ar...
View Full Document

Ask a homework question - tutors are online