Conditional Operator

Định nghĩa Conditional Operator là gì?

Conditional OperatorĐiều hành có điều kiện. Đây là nghĩa tiếng Việt của thuật ngữ Conditional Operator - một thuật ngữ thuộc nhóm Technology Terms - Công nghệ thông tin.

Độ phổ biến(Factor rating): 5/10

Một nhà điều hành có điều kiện trong C #, là một nhà điều hành mà mất ba toán hạng (điều kiện để được kiểm tra), giá trị khi điều kiện là đúng và giá trị khi điều kiện là sai. Một nhà điều hành có điều kiện được thể hiện bằng biểu tượng ':'. Các toán hạng đầu tiên (theo quy định trước khi ':') là đánh giá (có điều kiện) biểu. Nó phải được như vậy mà các loại biểu đánh giá có thể được ngầm chuyển đổi sang 'bool' hoặc dụng cụ điều hành đúng để tránh lỗi biên dịch. Các toán hạng thứ hai và thứ ba kiểm soát các loại biểu thức điều kiện. Nó thường được sử dụng trong nhiều nhiệm vụ chứ không phải là sản xuất tuyên bố lỗi biên dịch. Nếu giá trị trở lại của toán hạng đầu tiên (biểu thức điều kiện) là đúng, các toán hạng thứ hai được đánh giá. Nếu không, các toán hạng thứ ba được đánh giá. Do đó, kết quả của các nhà điều hành có điều kiện là kết quả của việc đánh giá của biểu thức xem xét để đánh giá. Đối với một biểu thức quy định như x a:? B, toán hạng một sẽ được đánh giá nếu chỉ toán hạng x (các biểu thức điều kiện) trả về true. Nếu không, toán hạng b sẽ được đánh giá. Thuật ngữ này cũng được biết đến như nhà điều hành ternary hoặc inline if (IIF).

Xem thêm: Thuật ngữ công nghệ A-Z

Giải thích ý nghĩa

Một nhà điều hành có điều kiện là các nhà điều hành chỉ ternary (dùng ba toán hạng) trong C #. Nó tạo thành như một thay thế cho các cấu trúc if-else, cung cấp conciseness tốt hơn với ít mã và khả năng đọc tốt hơn. Trong biên soạn, các biên dịch C # dịch biểu thức ternary vào báo cáo chi nhánh, có thể ngưng tụ nhiều nếu báo cáo và giảm làm tổ ở cấp độ của mã nguồn. Đôi khi, các mã được tạo cho một nhà điều hành ternary có thể tăng hiệu suất bằng cách sắp xếp lại một số các instructions.Properties của một nhà điều hành có điều kiện là:

What is the Conditional Operator? - Definition

A conditional operator in C#, is an operator that takes three operands (conditions to be checked), the value when the condition is true and value when the condition is false. A conditional operator is represented by the symbol '?:'. The first operand (specified before the '?:') is the evaluating (conditional) expression. It has to be such that the type of evaluated expression can be implicitly converted to 'bool' or that implements operator true in order to avoid compilation errors. The second and third operands control the type of conditional expression. It is more often used in assignment and not as a statement producing compilation errors. If the return value of the first operand (conditional expression) is true, the second operand is evaluated. Otherwise, the third operand is evaluated. Hence, the result of the conditional operator is the result of evaluation of the expression considered for evaluation. For an expression stated as x?a:b, operand a will be evaluated if only the operand x (the conditional expression) returns true. Otherwise, operand b will be evaluated. This term is also known as ternary operator or inline if (iif).

Understanding the Conditional Operator

A conditional operator is the only ternary operator (taking three operands) in C#. It forms as an alternative to the if-else construct, which provides better conciseness with less code and better readability. During compilation, the C# compiler translates the ternary expression into branch statements, which can condense multiple if statements and reduce nesting at the level of source code. Sometimes, the code generated for a ternary operator can boost performance by reordering some of the instructions.Properties of a conditional operator are:

Thuật ngữ liên quan

  • Null-Coalescing Operator
  • Else Statement
  • If Expression
  • Variable
  • Operator
  • Java
  • C# (C Sharp)
  • Operand
  • Commit
  • Access Modifiers

Source: ? Technology Dictionary - Filegi - Techtopedia - Techterm

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *