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 ...
随机推荐
- day22面向对象
面向对象编程: 1.什么是面向对象 面向过程(编程思想): 过程,解决问题的步骤,流程即第一步做什么,第二步做什么 将复杂问题,拆成若干小问题,按照步骤一一解决,将复杂问题流程化(为其制定固定的实现流 ...
- Lex与Yacc学习(五)之正则表达式篇
正则表达式语法 lex模式是由编辑程序和实用程序使用的正则表达式的扩展版本.正则表达式由常规字符(代表它们本身)和元字符(在一种模式中具有特殊含义)组成. 元字符 . . 匹配除了换行符 \n 之外的 ...
- 【HIHOCODER 1529】 不上升序列
描述 给定一个长度为 n 的非负整数序列 a[1..n]. 你每次可以花费 1 的代价给某个 a[i] 加1或者减1. 求最少需要多少代价能将这个序列变成一个不上升序列. 输入 第一行一个正整数 n. ...
- git克隆/更新/提交代码步骤及示意图
1. git clone ssh://flycm.intel.com/scm/at/atSrc 或者git clone ssh://flycm.intel.com/scm/at/atJar 或者g ...
- Java-使用哈希码比较对象的值
在一些特殊的情况下使用 package com.tj; import java.io.File; public class MyHash { public static void main(Strin ...
- deine const 等关键字区别
define 属于预编译指令,在程序运行之前就已经编译好:额,定义变量,没有类型信息, const 修饰的变量是不可变的,只是给出了内存地址,且只在程序运行时初始化开辟一块内存空间 const 只修饰 ...
- poj2104&&poj2761 (主席树&&划分树)主席树静态区间第k大模板
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 43315 Accepted: 14296 Ca ...
- nginx 的日志切割
nginx的日志切割脚本 说明:在nginx的配置文件中nginx.conf并没有定义access_log的位置, 在/usr/local/nginx/conf/vhost/下的配置文件中定义了acc ...
- MAC生成公钥私钥
前言 需要开发者在本地上使用openssl来生成私钥和公钥 由于mac 自带openssl工具,所以不用像windows那样要下载安装openssl工具 步骤 1.创建一个文件夹,终端进入该文件夹 c ...
- Mychael原创题 洛谷T23923 Mychaelの水题 【题解】
原题链接 题目大意: 有来自三个地区的人各a,b,c位,他们排成了一排.请问有多少种不同类型的排法,使得相邻的人都来自不同的地区 \(a,b,c<=200\) 答案取模 题解 弱弱的标程解法 设 ...