1 9/6/05CS360 Windows Programming CS360 Windows Programming.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Memory Management Chapter FourteenModern Programming Languages, 2nd ed.1.
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Introduction to Programming Lecture 39. Copy Constructor.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
Lecture 2 Basics of C#. Members of a Class A field is a variable of any type that is declared directly in a class. Fields are members of their containing.
Value Types and Reference Types Enumerations and Structures.
Implications of Substitution Fall 2005 OOPD John Anthony.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Programming in C# Language Overview
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Java2C# Antonio Cisternino Part II. Outline Array types Enum types Value types  differences from classes  boxing and unboxing Delegate types  Base.
Runtime Environments Compiler Construction Chapter 7.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
References types and Value types With a very brief introduction to struct and enum Reference types and Value types1.
C# Yingcai Xiao. Part I Moving from Java to C# .NET Framework ’ s Data Types: CTS Six categories of data types in CTS: system-defined: Primitives (int,
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Chapter 9 Pointers and Dynamic Arrays (9.1). Pointers A variables which holds the memory address for a variable of a specific type. Call-by-Reference.
Introduction to C#. Why C#? Develop on the Following Platforms ASP.NET Native Windows Windows 8 / 8.1 Windows Phone WPF Android (Xamarin) iOS (Xamarin)
Object Oriented Software Development
1 Enumerations and Structs Chapter 9. 2 Objectives You will be able to: Write programs that define and use enumeration variables. Write programs that.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
1 Structs. 2 Defining a Structure Often need to keep track of several pieces of information about a given thing. Example: Box We know its length width.
Introduction to Object-Oriented Programming Lesson 2.
Object Oriented Software Development 4. C# data types, objects and references.
From C++ to C# Part 5. Enums Similar to C++ Similar to C++ Read up section 1.10 of Spec. Read up section 1.10 of Spec.
Introduction to C# By: Abir Ghattas Michel Barakat.
Arrays  an array of 5 ints is filled with 3,2,4,1,7 int a[5] = {3,2,4,1,7}; // note squiggly brackets  an array of 3 floats is filled with 3.2,1.4,0;
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming(Objects& Class) Classes are an expanded concept of data structures: like.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
MORE POINTERS Plus: Memory Allocation Heap versus Stack.
Data Structures in C++ Pointers & Dynamic Arrays Shinta P.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Yingcai Xiao Programming and Debugging in Unity Yingcai Xiao.
Object Oriented Programming Lecture 2: BallWorld.
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
FASTFAST All rights reserved © MEP Make programming fun again.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming II 3 rd Lecture Pavel Ježek
Value Types. 2 Objectives Discuss concept of value types –efficiency –memory management –value semantics –boxing –unboxing –simple types Introduce struct.
Java Yingcai Xiao.
Programming and Debugging
Lectures linked lists Chapter 6 of textbook
Module 5: Common Type System
Methods Attributes Method Modifiers ‘static’
CS360 Windows Programming
C# for Unity3D Yingcai Xiao.
Conditional Statements
Pointers C#, pointers can only be declared to hold the memory addresses of value types int i = 5; int *p; p = &i; *p = 10; // changes the value of i to.
CS2011 Introduction to Programming I Arrays (II)
Programming and Debugging
C# Language & .NET Platform 10th Lecture
C# Language & .NET Platform 11th Lecture
C# Language & .NET Platform 9th Lecture
Interfaces, Enumerations, Boxing, and Unboxing
Presentation transcript:

1 9/6/05CS360 Windows Programming CS360 Windows Programming

2 9/6/05CS360 Windows Programming Last Week  We o Covered the principles behind web services o Introduced the.NET framework o Reviewed object-oriented programming o Started learning about C#

3 9/6/05CS360 Windows Programming C# Statements and Expressions  Very similar to C++, with some changes to increase robustness o No ‘->’ or ‘::’ ; all qualifications use ‘.’ o Local variables must be initialized before use o if, while, do require bool condition o goto can’t jump into blocks o switch statement – no fall through (empty case OK) o case labels can be strings

4 9/6/05CS360 Windows Programming Types  FCL is a library of types o Classes – today o Structs – today o Interfaces – next time o Enumerations – next time o Delegates – next time

5 9/6/05CS360 Windows Programming Classes  Classes contain o Fields - data members in C++ o Methods - member functions in C++ o Properties - expose data using get and set o Events - define notifications that class can hire

6 9/6/05CS360 Windows Programming Example class Rectangle { // Fields protected int width = 1; protected int height = 1; // Methods (constructors) public Rectangle () {} public Rectangle (int cx, int cy) { Width = cx; Height = cy; }

7 9/6/05CS360 Windows Programming Example (cont.) // Properties public int Width { get { return width; } set { if (value > 0) width = value; else throw new ArgumentOutOfRangeException ( "Width must be 1 or higher"); }

8 9/6/05CS360 Windows Programming Example (cont.) public int Height { get { return height; } set { if (value > 0) height = value; else throw new ArgumentOutOfRangeException ( "Height must be 1 or higher"); } public int Area { get { return width * height; } }

9 9/6/05CS360 Windows Programming Example (cont.) Rectangle rect = new Rectangle (); Rectangle rect = new Rectangle (3, 4); rect.Width *= 2; int area = rect.Area;

10 9/6/05CS360 Windows Programming Structs struct Point { public int x; public int y; public Point (int x, int y) { this.x = x; this.y = y; }

11 9/6/05CS360 Windows Programming Reference and Value Types  Classes are reference types  Structs are value types

12 9/6/05CS360 Windows Programming Common Type System Object ValueReference Built-in (primitive) data types Examples: int, double, … Size is specific Allocated on Stack Assignment copies value Cannot derive from other types User defined types: structs Deallocated when defining block exits Examples: Classes, Arrays, Interfaces, Delegates Allocated on managed heap Assignment copies reference Garbage collected

13 9/6/05CS360 Windows Programming Stack and Heap  Memory is a collection of bytes  Imagine each box as one byte long  Each byte can hold a number between Why?  Each byte has an address

14 9/6/05CS360 Windows Programming Stack and Heap  Whenever a variable is created it is added on to the stack  Variables are added sequentially (i.e. l-r, t-b)  No value for an empty byte  No holes allowed in memory. Why?  Stack pointer points to end of used memory A B C

15 9/6/05CS360 Windows Programming Stack and Heap  Problem: what do we do with dynamic variables?  Solution: use a heap  Stack is used for fixed size variables only  Stack pointer in first four bytes of stack A B B B C Stack pointer

16 9/6/05CS360 Windows Programming Stack and Heap  Variables created on the heap are scattered throughout the heap  Heap contains holes  Each variable has a header listing o Size of variable o Address of next variable stack heap

17 9/6/05CS360 Windows Programming Example Static void Main() { Ref r1 = new Ref(); Val v1 = new Val(); } Class Ref { public int x; } struct Val { public int x; } Stack Heap

18 9/6/05CS360 Windows Programming Example Static void Main() { Ref r1 = new Ref(); Val v1 = new Val(); } Class Ref { public int x; } struct Val { public int x; } Stack Heap r1 x = 0 v1 x = 0

19 9/6/05CS360 Windows Programming Example Static void Main() { Ref r1 = new Ref(); Val v1 = new Val(); r1.x = 5; v1.x = 5; } Class Ref { public int x; } struct Val { public int x; } Stack Heap r1 x = 5 v1 x = 5

20 9/6/05CS360 Windows Programming Example Static void Main() { Ref r1 = new Ref(); Val v1 = new Val(); r1.x = 5; v1.x = 5; Ref r2 = r1; Val v2 = v1; } Class Ref { public int x; } struct Val { public int x; } Stack Heap r1 x = 5 v1 x = 5 r2 x = 5 v2

21 9/6/05CS360 Windows Programming Summary  Completed p  Next time we will complete chapter 2