-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chapter27 初稿 #2
base: master
Are you sure you want to change the base?
Chapter27 初稿 #2
Conversation
## 本章中能学到的内容 | ||
什么是枚举? | ||
|
||
如何在 Go 语言中创建枚举 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如何在 Go 语言中创建一个枚举类型。
|
||
- 首先,我们声明了一个新的类型 `HTTPMethod`(其基础类型是整型 `int`)。 | ||
- 然后我们创建了9个 `HTTPMethod` 类型的常量 | ||
- 每个常量的类型都是 `HTTPMethod`,其命名方式与其指定的HTTP方法类似。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 每个常量都是
HTTPMethod
类型,并且我们用 HTTP 的方法名做为常量名。
- 然后我们创建了9个 `HTTPMethod` 类型的常量 | ||
- 每个常量的类型都是 `HTTPMethod`,其命名方式与其指定的HTTP方法类似。 | ||
|
||
### 为什么是整型? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么用整型做为基础类型?
|
||
### 使用示例 | ||
|
||
想象你现在有一个处理 HTTP 请求的函数,在这个函数中,你希望用户给你一个 HTTP 方法,并希望处理一组预定义的方法。那你的函数可以定义一个 `HTTPMethod` 类型的参数(也可以替换成整型 `int`): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
想象你现在有一个处理 HTTP 请求的函数。
在这个函数中,你希望预先定义好一组方法用于处理用户发送过来的 HTTP 请求。那你的函数可以定义一个 HTTPMethod
类型的参数(也可以替换成整型 int
):
|
||
1. Go语言版本 1 是否支持枚举类型? | ||
2. 代码中 `OptA` 的值是多少? | ||
3. 写出 AND,OR,XOR,NOT,AND NOT 的操作符号。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 写出 AND,OR,XOR,NOT,AND NOT 的按位操作符号。
2. 代码中 `OptA` 的值是多少? | ||
3. 写出 AND,OR,XOR,NOT,AND NOT 的操作符号。 | ||
4. `OptC` 是什么类型? | ||
5. 二进制数字向左移位的运算符是哪个? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 二进制数字向左移位的按位运算符是哪个?
3. 写出 AND,OR,XOR,NOT,AND NOT 的操作符号。 | ||
4. `OptC` 是什么类型? | ||
5. 二进制数字向左移位的运算符是哪个? | ||
6. 将二进制数字偏移到左边的运算符是哪个? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 将二进制数字偏移到左边的按位运算符是哪个?
5. AND NOT:`&^` | ||
4. `OptC` 是什么类型? | ||
1. `Elem` | ||
5. 二进制数字向左移位的运算符是哪个? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 二进制数字向左移位的按位运算符是哪个?
1. `Elem` | ||
5. 二进制数字向左移位的运算符是哪个? | ||
1. `<<` | ||
6. 将二进制数字偏移到左边的运算符是哪个? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 将二进制数字偏移到左边的按位运算符是哪个?
No description provided.