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 ...
随机推荐
- qt5.7.1 (create4.2.0)+msvc2015 安装后无法编译 & 缺少h文件
其实问题的本质是,系统中没有vs2015的注册信息导致 一开始是报: "'cl' 不是内部或外部命令,也不是可运行的程序"解决方案 通过在环境变量中添加了C:\Program Fi ...
- C/C++中容器vector用法
C++中数组非常坑,有没有相似Python中list的数据类型呢?相似的就是vector!vector 是同一种类型的对象的集合,每一个对象都有一个对应的整数索引值. 和 string 对象一样.标准 ...
- 消息中间件 MQ
复制粘贴于:https://blog.csdn.net/wqc19920906/article/details/82193316 一.消息中间件相关知识 1.概述 消息队列已经逐渐成为企业IT系统内部 ...
- MarkDownPad2基本语法
一.换行和空格 (1)换行 行尾加两个空格 (2)空格 二.标题 在#后跟个空格再写文字,一个#是一级标题,两个#是二级标题,以此类推,支持六级标题. 示例: # 一级标题 ...
- ansible 模块 分享
A a10_server 管理A10 Networks AX / SoftAX / Thunder / vThunder设备 a10_service_group 管理A10网络设备的服务组 a10_v ...
- nginx的概念与几种负载均衡算法
Nginx的背景 Nginx和Apache一样都是一种WEB服务器.基于REST架构风格,以URI(Uniform Resources Identifier,统一资源描述符)或URL(Uniform ...
- Django(八)下:Model操作和Form操作、序列化操作
二.Form操作 一般会创建forms.py文件,单独存放form模块. Form 专门做数据验证,而且非常强大.有以下两个插件: fields :验证(肯定会用的) widgets:生成HTML(有 ...
- 详解volatile 关键字与内存可见性
先来看一个例子: public class VolatileTest { public static void main(String[] args) { T ...
- ABP中的Filter(下)
接着上面的一个部分来叙述,这一篇我们来重点看ABP中的AbpUowActionFilter.AbpExceptionFilter.AbpResultFilter这三个部分也是按照之前的思路来一个个介绍 ...
- tensorflow-TensorBoard
Tensorborad--> 是Tensorflow的可视化工具,它可以通过Tensorflow程序运行过程中输出的日志文件可视化Tensorflow程序的运行状态.Tensorflow和Ten ...