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. 黑阔主流攻防之不合理的cookie验证方式

    最近博主没事干中(ZIZUOZISHOU),于是拿起某校的习题研究一番,名字很6,叫做黑阔主流攻防习题 虚拟机环境经过一番折腾,配置好后,打开目标地址:192.168.5.155 如图所示 这里看出题 ...

  2. CTF杂项之音频隐写

    题目来自bugku 二话不说,直接上图 由题目可以看出,这题需要用到一个KEY,加上又是一段音频,很容易联想到一个著名的音频隐写解密软件Mp3stego 直接上工具 ok,成功Get Flag

  3. Linux CentOS 6 解决 Device eth0 does not seem to be present

    一.故障现象: [root@c1node01 ~]# service network restart Shutting down loopback insterface:                ...

  4. Python之Pandas的一些理解

    Pandas的功能: 1.  结构化的数据分析; 相比excel,可以处理更大量的数据和更好的性能 2.  对数据的清洗

  5. 搭建IIS并配置网站之旅

    配置本地IIS这个过程,很羞愧的说,大概花了一个月之久…… 最开始,有需要用到了IIS,然后就着手配置,然后就遇到了问题,然后当时事很多,这又不是很急,就搁置了…… 在历经了一个月之后,现在又空余时间 ...

  6. Linux 系统假死的解决方案

    Linux 系统有时因为软件不兼容或未知 bug,导致系统假死.比如我的 Ubuntu 14.04 最近使用 vscode 时偶尔会导致系统假死,即鼠标可以移动,但点击无反应. 此时可试试如下解决方案 ...

  7. [翻译] ASP.NET Core 2.2 正式版发布

    本文为翻译,原文地址:https://blogs.msdn.microsoft.com/webdev/2018/12/04/asp-net-core-2-2-available-today/ 我(文章 ...

  8. keras02 - hello convolution neural network 搭建第一个卷积神经网络

    本项目参考: https://www.bilibili.com/video/av31500120?t=4657 训练代码 # coding: utf-8 # Learning from Mofan a ...

  9. OO第二单元总结——多线程电梯

    第五次作业分析 1.设计策略 调度器采用单例模式,内部设请求队列,对请求队列的一切操作(查.增.删)都在调度器内完成,且都要求串行,从而确保线程安全.接收器和电梯是两个线程:接收器接受请求调用调度器来 ...

  10. Win10 + MySQL + Tableu + PPT + 可视化方案

    1. 官网下MySQL 2. 解压到硬盘, 新建my.ini文件: [mysql] ; 设置mysql客户端默认字符集 default-character-set=utf8 [mysqld] ;设置3 ...