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 ...
随机推荐
- 【心得】Lattice和Xilinx工具关键特性对比(Diamond、ISE)
[博客导航] [导航]FPGA相关 背景 由于项目需要,初次接触Diamond,发现跟之前的ISE有很多不同,记录下一些体会,供参考.按开发流程,将一些常用的特性进行对比,列举如下: IP Core管 ...
- Fiddler-抓取手机app请求
如何使用 Fiddler 抓取手机app请求? 前提:手机和电脑在同一局域网 1.设置 Fiddler>Tools>Options>Connections 勾选 Allow remo ...
- npm基本操作(安装,搭建环境,打包)
Nodejs(npm)环境安装: npm的安装配置(从nodejs网站上安装npm): Windows安装Nodejs操作步骤如下: 64 位安装包下载地址 : https://nodejs.org/ ...
- C语言中printf,scanf,puts,%%等输出格式
#include<stdio.h> int main(void){ int a; printf("请输入一个整数,程序求取他的最后一位数字:"); s ...
- Vue — 微信公众号内置h5支付相关
首先,在公众号后台配置h5页面地址 开发流程 1.通过配置h5地址,获取code.再通过code,获取openid getOpenid(){ let url = 'https://open.weixi ...
- Servlet 易错点和注意点
目录 @WebServlet("/")与@WebServlet("/*")的区别 @WebServlet("/")与@WebServlet( ...
- 手指向上滑动跳转页面的JQ方法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- java &与&& |与||的区别
一.与操作和或操作的区别 (1)在Java程序中,使用与操作,要求所有表达式的判断结果都是TRUE,才为真,若有一个为FALSE,那么最终判断结果则为FALSE (2)使用或操作,只要其中有一个表达式 ...
- admin 配置
如何创建admin管理员 python manage.py createsuperuser #这里要注意python是环境变量中你设置的名字也可能是python2,python3 admin编程中文环 ...
- IntelliJ IDEA远程调试(Debug)Tomcat
为什么需要这么做? 解决 在我本地是好的啊 这个世界性难题- 测试环境碰到问题,直接连上debug,不用再测试本地,再查看测试环境日志 遇到一些诡异的问题,日志是看不出端倪的 调试一些只能在测试环境执 ...