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 ...
随机推荐
- block的注意点
1). 在block内部使用外部指针且会造成循环引用情况下,需要用__week修饰外部指针: __weak typeof(self) weakSelf = self; 2). 在block内部如果调用 ...
- Windows Server 2016-Telnet 简介及安装
Telnet是基于请求注释(RFC)854的因特网标准程序和协议,该RFC规定了一种在网络上发送和接收未加密的ASCII字符(明文)的方法.Telnet包含两个功能模块:Telnet客户端和Telne ...
- Airtest自动化测试工具
一开始知道Airtest大概是在年初的时候,当时,看了一下官方的文档,大概是类似Sikuli的一个工具,主要用来做游戏自动化的,通过截图的方式用来解决游戏自动化测试的难题.最近,移动端测试的同事尝试用 ...
- handsontable的基础应用
handsontable是一款页面端的表格式交互插件,可以通过她加载显示表格内容,能够支持合并项.统计.行列拖动等. 同时,支持对加载后的表格页面的处理:添加/删除行/列,合并单元格等操作. 我在项目 ...
- UML在代码中的展现
依赖:一个类使用了另外一个类,这种关系是临时的.脆弱的. 如人需要过河,需要船,这时人.过河(船) 中船被当做参数传入,船的实现变化会影响过河方法. 聚合:体现是整体与部分.has-a的关系 ...
- kvm虚拟化介绍
一.虚拟化分类 1.虚拟化,是指通过虚拟化技术将一台计算机虚拟为多台逻辑计算机.在一台计算机上同时运行多个逻辑计算机,每个逻辑计算机可运行不同的操作系统,并且应用程序都可以在相互独立的空间内运行而互相 ...
- Linux之判断字符串是否为空
help命令可以查看帮助 help test 正确做法: #!/bin/sh STRING= if [ -z "$STRING" ]; then echo "ST ...
- kettle变量(param命名参数2)
接arg参数: 通过命令行进行变量赋值和引用 定义跟界面定义相同: 赋值(转换): 运行命令到kettle目录下 pan /file:path "/param:aa="bb&quo ...
- golang核心Goroutine和channel
一.Goroutine 1.介绍 goroutine简介 goroutine是go语言中最为NB的设计,也是其魅力所在,goroutine的本质是协程,是实现并行计算的核心.goroutine使用方式 ...
- Leetcode 4.28 Tree Easy
1. 101. Symmetric Tree 用递归. class Solution { public boolean isSymmetric(TreeNode root) { if( root == ...