tailieunhanh - Programming C# - part 2

Tham khảo tài liệu 'programming c# - part 2', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Programming C 2nd Edition myAge The prefix and postfix operators To complicate matters further you might want to increment a variable and assign the results to a second variable firstValue secondValue The question arises do you want to assign before you increment the value or after In other words if secondVaiue starts out with the value 10 do you want to end with both firstvaiue and secondVaiue equal to 11 or do you want firstvaiue to be equal to 10 the original value and secondValue to be equal to 11 C again like C and C offer two flavors of the increment and decrement operators prefix and postfix. Thus you can write firstValue secondValue postfix which will assign first and then increment firstValue 10 secondValue 11 . You can also write firstValue secondValue prefix which will increment first and then assign firstValue 11 secondValue 11 . It is important to understand the different effects of prefix and postfix as illustrated in Example 3-17. Example 3-17. Illustrating prefix versus postfix increment using System class Values static void Main int valueOne 10 int valueTwo valueTwo valueOne After postfix 0 1 valueOne valueTwo valueOne 20 valueTwo valueOne After prefix 0 1 valueOne valueTwo Output After postfix 11 10 After prefix 21 21 54 Programming C 2nd Edition Relational Operators Relational operators are used to compare two values and then return a Boolean true or false . The greater-than operator for example returns true if the value on the left of the operator is greater than the value on the right. Thus 5 2 returns the value true while 2 5 returns the value false. The relational operators for C are shown in Table 3-3. This table assumes two variables bigValue and smallvalue in which bigVaiue has been assigned the value 100 and smallValue the value 50. Table 3-3. C relational operators assumes bigValue 100 and smallValue 50 Name Operator Given this statement The expression evaluates to Equals bigValue 100 .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã 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.