C# step by step 学习笔记8 CHAPTER 9 使用枚举和结构创建值类型
C# 2012 step by step 学习笔记8 CHAPTER 9 使用枚举和结构创建值类型
本章内容
- 声明一个枚举类型
- 创建并使用一个枚举类型
- 声明一个结构类型
- 创建并使用一个结构类型
- 解释结构和类之间行为的区别
声明一个枚举
使用枚举
modifier. You can then assign the null value, as well the values defined by the enumeration, to
the variable: Season?
colorful = null;
variables of the same type for equality by using the equality operator (==), and you can even perform arithmetic on an enumeration variable (although the result might not always be meaningful!).
Choosing enumeration Literal Values
Choosing an enumeration’s Underlying type
than an int, you can write this:
enum Season : short { Spring, Summer, Fall, Winter }
The main reason for doing this is to save memory; an int occupies more memory than a short, and if you do not need the entire range of values available to an int, using a smaller data type can make sense.
on the byte data type, you can have a maximum of 256 literals (starting at 0).
Working with Structures
the stack, as long as the structure is reasonably small, the memory management overhead is often reduced.
Common Structure types
of these types.
Declaring a Structure
to initialize and manipulate these fields。
can use the builtin Equals() method exposed by all structures to compare them, and you can also explicitly declare and implement operators for your own structure types. The syntax for doing this is covered in Chapter 22, “Operator Overloading.”
Understanding Structure and Class Differences
you fail to do this, you’ll get a compile-time error.
Declaring Structure Variables
Time? currentTime = null;
Understanding Structure Initialization
Copying Structure Variables
values).
Date copy = now;
an exception.
C# step by step 学习笔记8 CHAPTER 9 使用枚举和结构创建值类型的更多相关文章
- C#学习笔记10:Try-catch的用法和引用类型、值类型整理
Try-Catch: 将可能发生异常的代码放到try中,在catch中进行捕获. 如果try中有一行代码发生了异常,那么这行代码后面的代码不会再被执行了. Try写完了以后,紧接着就要写Catch ...
- Net基础篇_学习笔记_第十二天_面向对象继承(命名空间 、值类型和引用类型)
命名空间可以认为类是属于命名空间的. 解决类的重名问题,可以看做类的“文件夹”如果在当前项目中没有这个类的命名空间,需要我们手动的导入这个类所在的命名空间.1).用鼠标去点2).alt+shift+F ...
- 【Unity Shaders】学习笔记——SurfaceShader(二)两个结构体和CG类型
[Unity Shaders]学习笔记——SurfaceShader(二)两个结构体和CG类型 转载请注明出处:http://www.cnblogs.com/-867259206/p/5596698. ...
- cocos2d-x入门学习笔记,主要介绍cocos2d-x的基本结构,并且介绍引擎自带的示例
cocos2d-x 3.0 制作横版格斗游戏 http://philon.cn/post/cocos2d-x-3.0-zhi-zuo-heng-ban-ge-dou-you-xi http://blo ...
- C语言学习笔记10-结构体、枚举、联合体
C语言学习笔记10-结构体.枚举.联合体 待传
- Swift学习笔记(9):枚举
目录: 基本语法 关联值 原始值 枚举为一组相关的值定义了一个共同的类型. ・可以给枚举成员指定原始值类型:字符串,字符,整型值或浮点数等 ・枚举成员可以指定任意类型的关联值存储到枚举成员中 ・枚举可 ...
- Python学习笔记(1):列表元组结构
Python的列表元组功能强大,令人印象深刻.一是非常灵活,二是便于集体操作.特别是以元组作为列表项的结构,和数据访问的结果能够对应起来,和习惯的二维表理解上也一致,有很多的用途. 以学习笔记(3)中 ...
- [原创]java WEB学习笔记44:Filter 简介,模型,创建,工作原理,相关API,过滤器的部署及映射的方式,Demo
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- WebGL three.js学习笔记 法向量网格材质MeshNormalMaterial的介绍和创建360度全景天空盒的方法
WebGL学习----Three.js学习笔记(5) 点击查看demo演示 Demo地址:https://nsytsqdtn.github.io/demo/360/360 简单网格材质 MeshNor ...
随机推荐
- PAT Basic 1071
1071 小赌怡情 常言道“小赌怡情”.这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大还是小:玩家下注 t 个筹码后,计算机给出第二个数.若玩家猜对了,则 ...
- Python 描述符(Descriptor) 附实例
在 Python 众多原生特性中,描述符可能是最少被自定义的特性之一,但它在底层实现的方法和属性却无时不刻被使用着,它优雅的实现方式体现出 Python 简洁之美. 定义 一个描述符是一个有" ...
- HDU 4003 Find Metal Mineral
这个题是POJ1849的加强版. 先说一个很重要的结论,下面两种方法都是从这个结论出发的. 一个人从起点遍历一颗树,如果最终要回到起点,走过的最小权值就是整棵树的权值的2倍. 而且K个人的情况也是如此 ...
- linux中软件包管理
一.流行的软件包管理有两种: Debian Linux的Deb软件包和 Redhat Linux的Rpm软件包, Debian Linux首先提出将应用程序的二进制文件.配置文档.man/info帮助 ...
- 00032_ArrayList集合的遍历
1.通过集合遍历,得到集合中每个元素,这是集合中最常见的操作 2.集合的遍历与数组的遍历很像,都是通过索引的方式 public class ArrayListDemo02 { public stati ...
- Python开发:模块
在前面的几个章节中我们脚本上是用 python 解释器来编程,如果你从 Python 解释器退出再进入,那么你定义的所有的方法和变量就都消失了. 为此 Python 提供了一个办法,把这些定义存放在文 ...
- HTML与XML的区别
什么是HTML HTML的全拼是Hypertext Markup Language, 中文也就是超文本链接标示语言.HTML(HyperTextMark-upLanguage)即超文本标记语言,是WW ...
- 七、docker基本命令
Docker 基本命令 docker的基本命令 docker version :查看docker的版本号,包括客户端.服务端.依赖的Go等 [root@centos7 ~]# docker versi ...
- TOJ 5065: 最长连续子序列
5065: 最长连续子序列 Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit: 140 ...
- win10关闭防火墙命令
NetSh Advfirewall set allprofiles state off #关闭防火墙 Netsh Advfirewall show allprofiles #查看防火墙状态