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. 使用docker快速搭建nginx+php环境

    在朋友的强烈推荐下,走上了docker之路.经过了繁琐的docker环境安装,看了下镜像/容器的简单使用,开始进行nginx+php环境的搭建,本文记录一下在安装过程中的笔记. 原文地址:代码汇个人博 ...

  2. C++11のlambd表达式

    在其他语言中,我们常见lambda表达式,c++11中也引入了. 利用Lambda表达式,可以方便的定义和创建匿名函数.今天,我们就来简单介绍一下C++中Lambda表达式的简单使用. 一.lambd ...

  3. yaml的用法

    yaml是用来读配置文件的. 一般用yaml或者yml结尾创建文件,格式:key: value.然后在用的时候,像打开文件一样读,返回数据可直接转为字典 使用的时候必须先安装模块并导入.安装:pip ...

  4. Map the Debris 轨道周期

    返回一个数组,其内容是把原数组中对应元素的平均海拔转换成其对应的轨道周期. 原数组中会包含格式化的对象内容,像这样 {name: 'name', avgAlt: avgAlt}. 至于轨道周期怎么求, ...

  5. Flask自定义转换器,实现路由匹配正则表达式参数

    Flask框架动态路由实现参数传递和Django框架有类似之处,但是相比于Django框架,Flask实现复杂的参数就需要自己自定义转换器来实现了,而不能向Django那样直接使用正则表达式 # 路由 ...

  6. LVS实现负载均衡安装配置详解

    =========实践LVS/NAT模式========== 1.实验环境 三台服务器,一台作为 director,两台作为 real server,director 有一个外网网卡(172.16.2 ...

  7. web开发中各种宽高

    Gosper 曲线:https://www.cnblogs.com/tgzhu/p/8286616.html

  8. Ubuntu 16.04 安装opencv3.4.5/cuda/caffe并使用jni笔记

    因操作失误,误卸开发机NVIDIA显卡驱动,先更新操作日志如下: 1>NVIDIA驱动重装 1.卸载系统里的Nvidia残余 sudo apt-get purge nvidia* 2.把显卡驱动 ...

  9. Spring cloud zuul跨域(二)

    使用  CorsFilter  解决ajax跨域问题 直接在zuul的main下面,创建corsFilter就可以了. @SpringBootApplication @EnableZuulProxy ...

  10. [UVa-437] Color Length

    无法用复杂状态进行转移时改变计算方式:巧妙的整体考虑:压缩空间优化时间 传送门:$>here<$ 题意 给出两个字符串a,b,可以将他们穿插起来(相对位置不变).要求最小化ΣL(c),其中 ...