C# 01 Primitive Types and Expressions
Class
- Data or Attributes
- state of the application
- Methods or Functions
- have behavior
Namespace
- is a container for related classes
Assembly (DLL or EXE)
- is a container for related namespaces
- is a file which can either be a EXE or a DLL
Application
- include one or more assemblies
Primitive Types (C# type)
- Integral Number
- byte (1byte, Max is 255)
- short
- int
- long
- Real Numbers
- float (4byte)
- double
- decimal
- Character
- char (2byte)
- Boolean
- bool (1byte)
- good practice
- Prefix Boolean names with is or has
- For example: isOver18, isCitizen, isEligible
Something tricky about real numbers
- data type is double by default
- wrong
float number = 1.2; decimal number = 1.2;
- right
float number = 1.2f; decimal number = 1.2m;
Non-Primitive Types
- String
- Array
- Enum
- Class
Overflowing
- for example
byte number = ; number = number + ; //
- if you use check keyword, overflow will not happen and instead the program will throw an exception (But don't use it in real world )
Scope
- where a variable / constant has meaning
Type Conversion
- implicit type conversion
byte a = ;
int b = a;
- explicit type conversion (casting)
int c = ;
byte d = (byte)c;
- conversion between non-compatible types
string e = "";
int f = int.Parse(e) var a = "";
int b = Convert.ToInt32(a);
C# Operators
- Arithmetic Operators
- +
- -
- *
- /
var a = ;
var b = ;
Console.WriteLine(a+b); //
Console.WriteLine((float)a / (float)b); // 3.333333
- %
- Postfix increment
int a = ;
int b = a++; //b = 1, a = 2;
- Prefix increment
int a = ; int b = ++a; //b = 2, a = 2;
- Comparison Operators
- ==
- !=
- >
- >=
- <
- <=
- Assignment
- =
- +=
- -=
- *=
- /=
- Logical Operator
- &&
- And
- double ampersand
- a&&b
- ||
- Or
- double vertical line
- a||b
- !
- Not
- exclamation mark
- !a
- &&
- Bitwise Operators
- & And
- | Or
Comments
- Single-line Comment
// Here is a single-line comment
- Multi-line Comments
/* Here is a multi-line comment */
- When to use comments
- to explain whys, hows, constrains, etc
- Not explain the whats.
- comment do not explain what the code is doing
C# 01 Primitive Types and Expressions的更多相关文章
- Java中的原始类型(Primitive Types)与引用类型(Reference Values)
Java虚拟机可以处理的类型有两种,一种是原始类型(Primitive Types),一种是引用类型(Reference Types). 与之对应,也存在有原始值(Primitive Values)和 ...
- Effective Java 49 Prefer primitive types to boxed primitives
No. Primitives Boxed Primitives 1 Have their own values Have identities distinct from their values 2 ...
- Implement Hash Map Using Primitive Types
A small coding test that I encountered today. Question Using only primitive types, implement a fixed ...
- Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context.
代码如下: var query = from s in db.LoginUserServices join ss in db.Services on s.ServiceType equals ss.C ...
- CLR via C# 3rd - 05 - Primitive, Reference, and Value Types
1. Primitive Types Any data types the compiler directly supports are called primitive types. ...
- 5.Primitive, Reference, and Value Types
1.Programming Language Primitive Types primitive types:Any data types the compiler directly supports ...
- Primitive Data Types
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics) http ...
- 反射01 Class类的使用、动态加载类、类类型说明、获取类的信息
0 Java反射机制 反射(Reflection)是 Java 的高级特性之一,是框架实现的基础. 0.1 定义 Java 反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对 ...
- Effective Java 26 Favor generic types
Use generic types to replace the object declaration Add one or more type parameters to its declarati ...
随机推荐
- 网页验证码出不来,读取验证码时出错:javax.imageio.IIOException: Can't create cache file!
版权声明:本文为博主原创文章,仅作为学习交流使用 转载请注明出处 https://www.cnblogs.com/linck/p/10593053.html 今天打开项目时,发现登陆界面的验证码出不来 ...
- #033 信安培训基础题Python解决网络安全实验室|网络信息安全攻防学习平台
第三题猜猜这是经过了多少次加密?分值: 200 加密后的字符串为:一大串 字符串最后面是= 所以是base64.b64decode编码究竟为啥有=就是base64咱也不知道 咱也不敢问咋解密也是从网上 ...
- 编译安装redis-5.0.4
编译安装为redis官方推荐安装方式. 本例中使用linux版本为:CentOS Linux release 7.0.1406 (Core),Basic Web Server 一.安装依赖包 yum ...
- JDK8中HashMap
引用别人的一句话: JDK1.6,JDK1.7中,HashMap采用位桶+链表实现,即使用链表处理冲突,同一hash值的链表都存储在一个链表里.但是当位于一个桶中的元素较多,即hash值相等的元素较多 ...
- Python协程的引入与原理分析
相关概念 并发:指一个时间段内,有几个程序在同一个cpu上运行,但是任意时刻只有一个程序在cpu上运行.比如说在一秒内cpu切换了100个进程,就可以认为cpu的并发是100. 并行:值任意时刻点上, ...
- 完全自主创建Wrapper Tomcat容器
Wrapper Tomcat 使用说明1. Wrapper Tomcat 简介1) Wrapper Tomcat 是使用Apache Tomcat 整合 Java Service Wrapper 的一 ...
- React生命周期详解
React生命周期图解: 一.旧版图解: 二.新版图解: 从图中,我们可以清楚知道React的生命周期分为三个部分: 实例化.存在期和销毁时. 旧版生命周期如果要开启async rendering, ...
- 收藏了8年的PHP优秀资源,都给你整理好了
https://segmentfault.com/a/1190000018071558 最后更新于 2019.02.12 以下是我整理好的 PHP 资源,各位看官拿去用,不用再自己找了. 每周在 Gi ...
- Promise async-await 异步解决方案
1.简介: async和await在干什么,async用于申明一个function是异步的,而await可以认为是async wait的简写,等待一个异步方法执行完成. 2.基本语法 在C ...
- 解决CentOS6.5下MySQL5.6无法远程连接的问题
在CentOS6.5上安装了Mysql5.6,,本地服务启动成功,但是远程使用Navicat无法远程连接到MySQL数据库,为了解决这个问题,方法如下: (1)先将MySQL服务停掉# service ...