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的更多相关文章

  1. Java中的原始类型(Primitive Types)与引用类型(Reference Values)

    Java虚拟机可以处理的类型有两种,一种是原始类型(Primitive Types),一种是引用类型(Reference Types). 与之对应,也存在有原始值(Primitive Values)和 ...

  2. 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 ...

  3. Implement Hash Map Using Primitive Types

    A small coding test that I encountered today. Question Using only primitive types, implement a fixed ...

  4. 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 ...

  5. CLR via C# 3rd - 05 - Primitive, Reference, and Value Types

    1. Primitive Types        Any data types the compiler directly supports are called primitive types. ...

  6. 5.Primitive, Reference, and Value Types

    1.Programming Language Primitive Types primitive types:Any data types the compiler directly supports ...

  7. Primitive Data Types

    Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics) http ...

  8. 反射01 Class类的使用、动态加载类、类类型说明、获取类的信息

    0 Java反射机制 反射(Reflection)是 Java 的高级特性之一,是框架实现的基础. 0.1 定义 Java 反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对 ...

  9. Effective Java 26 Favor generic types

    Use generic types to replace the object declaration Add one or more type parameters to its declarati ...

随机推荐

  1. React---入门(1)

    React是什么? React 是一个用于构建用户界面的 JAVASCRIPT 库. React 特点 1.声明式设计 −React采用声明范式,可以轻松描述应用. 2.高效 −React通过对DOM ...

  2. zabbix调用api检索方法

    环境 zabbix:172.16.128.16:zabbix_web:172.16.16.16/zabbix 用户名:Admin 密码:zabbix 获取的数据仅做参考,以Linux发送HTTP的PO ...

  3. Linux(CentOS7)压缩和解压缩war包、tar包、tar.gz包命令

    一.Linux版本 二.解压缩.tar.gz包到当前目录 tar -xzvf apache-tomcat-7.0.90.tar.gz 三.将指定文件压缩成.tar.gz包 tar -czf apach ...

  4. Jsp的基本知识

    jsp页面的基本组成部分:指令,表达式,小脚本,声明,注释,静态内容. 指令元素有三种: 1.page:eg <%@ page 属性名="属性值" 属性名="属性值 ...

  5. idea右键无法生成javaclass

    博客转自:https://www.cnblogs.com/zjfjava/p/9219237.html 项目中新建目录之后,要在该目录下新增java Class文件,右键——>New发现无对应选 ...

  6. CentOS7.x编译安装zabbix4.0

    编译安装zabbix Zabbix简介 Zabbix 是一个企业级的分布式开源监控方案. Zabbix是一款能够监控各种网络参数以及服务器健康性和完整性的软件.Zabbix使用灵活的通知机制,允许用户 ...

  7. 使用axios 的post请求下载文件,

    axios({ method: 'post', data: param, responseType:'blob', url: _urls + '/Downloaddata' }).then(data= ...

  8. Linux SHELL中sh和bash的区别

    什么是SHELL? shell的中文意思就是贝壳,其实比较类似于我们内核的壳.简而言之就是只要能够操作应用程序的接口都能够称为SHELL.狭义的shell指的是命令行方面的软件,广义的SHELL则包括 ...

  9. 02-Django框架介绍

    02-Django框架介绍 1.MVC框架介绍 MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创建 Web 应用程序的模式 具有耦合性低.重用性高.生 ...

  10. 浅谈css3有意思的属性pointer-events: none;

    pointer-events: none: 可以让某个元素实现类似于海市蜃楼的效果,具体理解为,你可以看的到某个元素,但是你无法摸的着.   而display:none; 是你摸不着,但是你也看不见. ...