Part 1 Introduction

The struct of C# program:

namespace , class and Main method

what is namespace?

the namespace declaration, using System, indicates that you are using the System namespace.

A namespace is used to organize your code and is collection of classes, interfaces, structs,enums and delegates.

Main method is the entry point into your application

Part 2 Reading and writing to a console

Reading from the console and Writing to the console

2 ways to write to console

a) Concatenation(+)

b) Place holder syntax -Most Preferred(占位符 ,推荐用这种)

C# is case sensitive (对大小写敏感)

Part 3  Built - in types

Boolean type --Only true or false

Integral Types --sbyte,byte,short,ushort,int,uint,long,ulong,char. how to know Integral Types Value? using MinValue and MaxValue property

Floating Types--float and double  , double type is default type ,if you want to declare a float type ,you should add F at end ,else,it will get an error

Decimal Types

String Type

Part 4 String type in c#

talk about escape \n,\',\" and etc. sometimes using @ to not escape(转义)

Part 5 Common Operators in c#

Assignment operator =(赋值运算符)

Arithmetic operator +,-,*,/,%

Comparison operator like == , != , > , >= , < <=

Conditional operator like && , ||

Ternary operator ?:

Null coalescing operator ??

Part 6 Nullable Types

Types in C#

In C# types are divided into 2 broad categories

Value Types --int, float, double, structs, enums etc

Reference Types -- Interface, Class, Delegetes, arrays etc

By default value types are non nullable. To make them nullable use?

int i = 0(i is non nullable, so i cannot be set to null, i = null will generate compiler error)

int? j = 0(j is nullable int, so j = null is legal)

Nullable types bridge the differences between C# types and Database types

about ?? operator , eg: int? i = 100 or null, int j = i ?? 0. it means if i is null, then j = 0 ,else ,j=i

Part 7 Datatypes conversion

Implicit conversions(隐式)

Explicit conversions(显式)

Difference between Parse() and TryParse()

implicit & explicit conversion

implicit conversion is done by the complier:

1, when there is no loss of information if the conversion is done

2,if there is no possibility of throwing exceptions during the conversion

Converting an int to a float will not loose any data and no exception will be thrown, hence(因此) an implicit conversion can be done.

Implicit Conversion Example:

int a = 10;
float b = a;//float is bigger datatype than int, so, no loss of data and exceptions, hence this is implicit conversion.

Where as when converting a float to an int , we loose the fractional(小数点后的数) part and also a possibility of overflow exception. Hence, in this case an explicit conversion is required. For explicit conversion we can use cast operator or the convert class in C#

Example:

float a =3.14F;
int b =(int)a;//use explicit conversion using cast() operator
int b = Convert.ToInt32(a);//use convert class

Diffrence between Parse(解析) and TryParse

if the number is in a string format you have 2 options --int.Parse() and int.TryParse()

Parse() method throws an exception if it cannot parse the value, where as TryParse() returns a bool indicating whether it succeeded or failed , so ,Use Parse() if you are sure the vlue will be valid, Otherwise, use TryParse()

Example:

string a ="100";
string a1="100e";
int result = 0;
int b = int.Parse(a);//it will be success.
int b1 =int.Parse(a1) //it will throw an exception.
bool isConvertSuccessful= int.TryParse(a1,out result);//no matter convert success or fail,it will not throw an exception.
if(isConvertSuccessful)
Consolve.Write(result);
else
Consolve.Write("convert fail");

Part 8 Arrays in C#

an array is a collection of similar data types.

Advantages:Arrays are strongly typed.

Disadvantages:Arrays cannot grow in size once initialized.

Have to rely on integral indices to store or retrieve items from the array.(必须依靠索引来存储或检索项目从数组。)

Example for declare an array:

int[] numbers = new int[3];
numbers[1]=1;
numbers[2]=2;
numbers[3]=3; int[] numbers1 = {1,2,3};

Part 9 Comments in C#

single line Comments        -//

Multi line Comments        -/* */

XML Documentation Comments   -///  if using this comment ,when you mouseover it ,it can show comment to you

Comment are used to document what the program does and what specific blocks or lines of code do. C# complier ignores comments

To Comment and Uncomment , there are 2 ways

1, Use the designer

2, Keyboard Shortcut: use Ctrl+K or Ctrl+C to comment and use Ctrl+K or Ctrl+U to uncomment

Note:Don't try to comment every line of code. User comments only for blocks or lines of code that are difficult to understand

Part 10  If statement in C#

if statement

if else statement

Difference between && and &

Difference between || and |

take example:

int number = int.TryParse(Cosole.ReadLine());

if(number ==0 && number ==10)  //if number >0,it will not exce condition number ==10

if(number ==0 & number ==10)  // though number>0 it will exce condition number==10,so, it is one more step than &&. the meaning about || and | also like that.

Part 1 to 10 Basic in C#的更多相关文章

  1. Cheatsheet: 2013 10.09 ~ 10.23

    Other 10 Basic Linux Networking and Monitoring Commands You Should Know A simple, portable yet effic ...

  2. c++(基数排序)

    基数排序是另外一种比较有特色的排序方式,它是怎么排序的呢?我们可以按照下面的一组数字做出说明:12. 104. 13. 7. 9 (1)按个位数排序是12.13.104.7.9 (2)再根据十位排序1 ...

  3. 【深度学习】Pytorch 学习笔记

    目录 Pytorch Leture 05: Linear Rregression in the Pytorch Way Logistic Regression 逻辑回归 - 二分类 Lecture07 ...

  4. 使用Maven命令行快速创建项目骨架(archetype)

      > mvn archetype:generate 接下来就会输出一些列带索引变化的archetype项可供我们选择,然后提示我们选择一个编号,可以直接回车选择默认的编号(392),然后就跟着 ...

  5. 机器人研发十大热门编程语言:不死 Java、不朽 C/C ++、新贵 Python

    流水的编程语言,铁打的 Java.C/C++. 进行人工智能机器人研发,应该选择哪种编程语言? 这是很多机器人专家在自身的职业生涯中都会存在的一个入门级思考.毕竟,在学习一门编程语言时,需要花费大量的 ...

  6. LSTM与Highway-LSTM算法实现的研究概述

    LSTM与Highway-LSTM算法实现的研究概述 zoerywzhou@gmail.com http://www.cnblogs.com/swje/ 作者:Zhouwan  2015-12-22 ...

  7. 天气预报APP(1)

    一个天气预报APP至少应该具备以下功能: *可以罗列出全国所有的省.市.县: *可以查看全国任意城市的天气信息: *可以自由的切换城市,去查看其他城市的天气: *提供手动更新以及后台自动更新天气的功能 ...

  8. Leetcode: Campus Bikes II

    On a campus represented as a 2D grid, there are N workers and M bikes, with N <= M. Each worker a ...

  9. scrapydWeb安装和使用

    1. 安装:pip install scrapydweb 2. 启动:scrapydweb 第一次执行,当前目录会生产配置文件:scrapydweb_settings_v8.py 配置账户和密码: # ...

随机推荐

  1. 2021“MINIEYE杯”中国大学生算法设计超级联赛(8)(1002,1004,1006,1009)

    前言 依旧是白嫖账号,只打了一些题/kk 正题 1002 Buying Snacks 题目大意 \(n\)个物品,每个可以买一次也可以不买,如果买需要选择\(1/2\)块钱的,然后也可以相邻两个一起买 ...

  2. Css预编译(Sass&&Less)

    目录 Less与Sass是css的预处理技术 而CoffeeScript.TypeScript则是javascript的预处理技术. Less与Sass是css的预处理技术 而CoffeeScript ...

  3. c++ 的学习 构造函数1

    1. 构造函数(也叫构造器),在对象创建的时候自动调用,一般用于完成对象的初始化工作 2.一旦自定义了构造函数,必须用其中一个自定义的构造函数来初始化对象 就是有多个的话    根据参数编译器自行选 ...

  4. python3 拼接字符串方法

    python3.x拼接字符串一般有以下几种方法: 1. 直接通过(+)操作符拼接 1 2 s = 'Hello'+' '+'World'+'!' print(s) 输出结果:Hello World! ...

  5. 论文解读(MPNN)Neural Message Passing for Quantum Chemistry

    论文标题:DEEP GRAPH INFOMAX 论文方向:  论文来源:ICML 2017 论文链接:https://arxiv.org/abs/1704.01212 论文代码: 1 介绍 本文的目标 ...

  6. DL4J实战之六:图形化展示训练过程

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本篇是<DL4J实战>系列的第六 ...

  7. oo第一次博客-三次表达式求导的总结与反思

    一.问题回顾与基本设计思路 三次作业依次是多项式表达式求导,多项式.三角函数混合求导,基于三角函数和多项式的嵌套表达式求导. 第一次作业想法很简单,根据指导书,我们可以发现表达式是由各个项与项之间的运 ...

  8. DDD领域驱动设计-案例建模设计-Ⅲ

    1. 背景 参考<DDD领域驱动设计-案例需求文档>,本文将构建实体,聚合根详述领域驱动中的建模设计.构建实体,聚合根的一些原则或方法,将在后续文章中说明. 2. 建模设计 2.1. 实体 ...

  9. Spring Cloud Alibaba 介绍及工程准备

    简介 SpringCloud Alibaba是阿里巴巴集团开源的一套微服务架构解决方案. 微服务架构是为了更好的分布式系统开发,将一个应用拆分成多个子应用,每一个服务都是可以独立运行的子工程.其中涵盖 ...

  10. [暴力题解&&考试反思] 双十一欢乐赛(联赛膜你测试32)

    前言: 今天考试很迷糊.从7点考到11点半,我大概从7点睡到9点.隐隐约约看到旁边的狗哥敲了好几个题,我才开始写代码.然后因为还是很困,而且T1迷迷糊糊调了好长时间,T3T4的暴力就懒的写了... 估 ...