Chương 2: Core C# Programming Construct

This chapter surveys the C# language syntax. I introduce you to the two fundamental kinds of types within the CLR: value types and reference types. This chapter also describes namespaces and how you can use them to logically partition types and functionality within your applications. | Hoang Anh Viet VietHA@ HaNoi University of Technology Chapter 2. Core C# Programming Constructs 3. Data Types 2008 © 2008 Microsoft Objectives “This chapter surveys the C# language syntax. I introduce you to the two fundamental kinds of types within the CLR: value types and reference types. This chapter also describes namespaces and how you can use them to logically partition types and functionality within your applications.” Roadmap . C# Is a strongly Typed Language . Expression . Statements and Expressions . Types and Variabless . NameSpaces . Control Flows . C# Is a strongly Typed Language Every variable and object instance in the system is of a well-defined type This enables the compiler to check that the operations to perform on variables and object instance are valid It is always best to find bugs at compile time rather than run time Example: Method ComputeAvg(): computes the average of two integers and returns the result double ComputeAvg( int param1, int param2 ) { return (param1 + param2) / ; } object ComputeAvg( object param1, object param2 ) { return ((int) param1 + (int) param2) / ; } ComputeAvg accepts two integers and returns a double. If passing an instance of Apple type, the compiler will complain and stop Convert objects into integers Passing an instance of Apple type causes an exception( the instance can’t be convert into integer object keyword: an alias of class Object is not a numeric type Roadmap . C# Is a strongly Typed Language . Expression . Statements and Expressions . Types and Variabless . NameSpaces . Control Flows . Expressions Expressions in C# are identical to expressions in C++ and Java. Are built using operands, eg. variables or types within an application, and operators Operators can be overloaded Operators can have different meaning in different contexts Eg: the + operator can mean string concatenation using with string operands | Hoang Anh Viet VietHA@ HaNoi University of Technology Chapter 2. Core C# Programming Constructs 3. Data Types 2008 © 2008 Microsoft Objectives “This chapter surveys the C# language syntax. I introduce you to the two fundamental kinds of types within the CLR: value types and reference types. This chapter also describes namespaces and how you can use them to logically partition types and functionality within your applications.” Roadmap . C# Is a strongly Typed Language . Expression . Statements and Expressions . Types and Variabless . NameSpaces . Control Flows . C# Is a strongly Typed Language Every variable and object instance in the system is of a well-defined type This enables the compiler to check that the operations to perform on variables and object instance are valid It is always best to find bugs at compile time rather than run time Example: Method ComputeAvg(): computes the average of two integers and returns the result .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.