type
status
date
slug
summary
tags
category
icon
password
Property
Jul 24, 2023 02:56 AM
本节内容
表达式的定义
各类表达式概览
语句的定义
语句详解
表达式的定义
什么是表达式
- 表达式是一种专门用来求值的语法实体。
- Expressions, together eith commands and declarations,are one of the basic components of every programming language.We can say that expressions are the essential commponent of every language.
- An expressions is a syntatic entity whose evaluation eithrt produces a value or fails to terminate, inwhich case the expression is undefined.
- 各种编程语言堆表达式的实现不尽相同,但大体上都符合这个定义。
C#语言低表达式的定义
- An expression is a sequence of one or more operators and zerp pr more operator that can be evaluated to a single value,object,method, or namespace. Expressions can consist of literal value, a method invocation, an operator and its operands, or a simple name. Simple names can be the name od a variable, type member, method parameter, namespace or type.
- 算法逻辑的最基本(最小)单元,表达一定的算法意图
- 因为操作符有优先级,所以表达式也就有了优先级
各类表达式概览
C#语言中表达式的分类
- A value. Every value has an associated type.任何能得到值的运算(回顾操作符和结果类型)
- A variable。Every variable has an associated type.
- A namespace.
- A type.
- A method group.例如:Console.WriteLine,这是一组方法,重载决策决定调用哪一个
- A null literal.
- An anonymous function.
- A property access.
- An event access.
- An indexer access.
- Nothing. 对返回值为void的方法的调用。
复合表达式的求值
- 注意操作符的优先级和同优先级操作符的运算方向
参考C#语言定义文档
- 仅做参考,不必深究–毕竟我们是在学习语言,不是去实现这门语言
注意 三元?:最后获得的类型是精度高的类型。
- 作者:Kitety
- 链接:https://www.kitety.com/article/C-sharp-leraning-expression-1
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
相关文章