PDN-C2-PPT - Chapter 2 Chapter 2 Types &...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: Chapter 2 Chapter 2 Types & Exceptions Types & Exceptions Yingcai Xiao Yingcai Xiao What you should do to design a language? How can you design a language? Computer: a device for data processing storing and processing data Programming = Data Structures + Algorithms Computer Languages: tools for users to define data structures to store the data and to develop algorithms to process the data. Data Types: System-defined Types & User-defined Types Data Structures + Algorithms .NET Frameworks Data Types: CTS Six categories of data types in CTS: system-defined: Primitives (int, float, ) user-defined: Classes Structs Interfaces Enumerations Delegates Common Type System (CTS) Named Space: grouped code, used to resolve naming conflicts. namespace mine { int i=10; } namespace his { int i=20; } mine.i = his.i; Common Type System (CTS) namespace WP1.CS.UA { class Hello { public Hello() { System . Console.WriteLine("Hello, world."); } } } namespace WP2.CS { class Hello { public Hello() { System . Console.WriteLine("Hello, again!"); } } } Named Space Example namespace WP { class Test { public static void Main() { WP1.CS.UA.Hello mc = new WP1.CS.UA.Hello(); WP2.CS.Hello mc2 = new WP2.CS.Hello(); } } } Named Space Example Classes Class: a group of code and data to be instantiated to form objects. Four categories of class members: Fields : member variables Methods : member functions Properties : fields exposed using accessor (get and set) methods Events : notifications a class is capable of firing class Rectangle { // Fields protected int width = 1; protected int height = 1; // Methods public Rectangle () { } public Rectangle (int cx, int cy) { width = cx; height = cy; } Example: How to define a class (user-defined data type) // Accessor Methods public void setWidth(int w) { width = w; } public int getWidth() { return width; } public void setHeight(int h) { height = h; } public int getHeight() { return height; } } // End of Rectangle class Example: How to define a class (user-defined data type) Rectangle rect = new Rectangle(2,4); rect.setHeight(8); rect.setWidth(rect.getWidth() * 2); double darea = (double) (rect.getWidth() * rect.getHeight() ); We protected member fields: width and height. (Encapsulation) (1) Securer code. Methods not belonging to the class hierarchy cant access protected members. If we dont want anyone change the value of width, we just dont provide the setWidth() method....
View Full Document

This note was uploaded on 02/21/2011 for the course CS 573 taught by Professor Dr.xiao during the Spring '10 term at The University of Akron.

Page1 / 71

PDN-C2-PPT - Chapter 2 Chapter 2 Types &...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online