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. 基于IPv6的数据包分析(第三组)

    一.实验拓扑 二.配置过程 本处提供R1.R2.R4的详细配置过程(包含静态路由的配置) 1)      R1: R1(config)#int e1/0 R1(config-if)#ipv6 addr ...

  2. June. 25th 2018, Week 26th. Monday

    Change in all things is sweet. 有改变就会有美好. From Aristole. Change is always good, but embracing change ...

  3. 接口(迭代器) Iterator

    Iterator接口简介 在程序开发中,经常需要遍历集合中的所有元素.针对这种需求,JDK专门提供了一个接口java.util.Iterator.Iterator接口也是Java集合中的一员,但它与C ...

  4. Tomcat FAIL - Deploy Upload Failed, Exception: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (110960596) exceeds the confi

    https://maxrohde.com/2011/04/27/large-war-file-cannot-be-deployed-in-tomcat-7/ Go to the web.xml of ...

  5. Jmeter单个长连接发送多个Sample

    Mark自:https://blog.csdn.net/lykangjia/article/details/16337505 1. 线程组,在我们测试方案里面,每个线程模拟一个用户,执行用户的登录.等 ...

  6. JavaScript的数据结构和算法

    所有JavaScript对象都有hasOwnProperty(value)的方法,用来返回一个表明对象是不是具有这个value Key值属性的布尔值. javaScript的方法 具有delete的方 ...

  7. [官网]Windows modules

    Windows modules https://docs.ansible.com/ansible/latest/modules/list_of_windows_modules.html win_acl ...

  8. Url校验正则

    最近需要对HTTP请求合法性做一些校验,在网上查找了一些关于URL合法性的正则表达式. 在github上的有个关于weburl匹配的gist: https://gist.github.com/dper ...

  9. C#中字符串转日期类型

    1,yyyyMMdd DateTime date = DateTime.ParseExact(", "yyyyMMdd", System.Globalization.Cu ...

  10. Vue.js 2.x笔记:组件(5)

    1. 组件简介 组件(Component)是 Vue.js 最强大的功能之一,组件可以扩展 HTML 元素,封装可重用的代码. 组件:为了拆分Vue实例的代码量,以不同的组件来划分不同的功能模块,需要 ...