Part 1 to 10 Basic in C#
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#的更多相关文章
- Cheatsheet: 2013 10.09 ~ 10.23
Other 10 Basic Linux Networking and Monitoring Commands You Should Know A simple, portable yet effic ...
- c++(基数排序)
基数排序是另外一种比较有特色的排序方式,它是怎么排序的呢?我们可以按照下面的一组数字做出说明:12. 104. 13. 7. 9 (1)按个位数排序是12.13.104.7.9 (2)再根据十位排序1 ...
- 【深度学习】Pytorch 学习笔记
目录 Pytorch Leture 05: Linear Rregression in the Pytorch Way Logistic Regression 逻辑回归 - 二分类 Lecture07 ...
- 使用Maven命令行快速创建项目骨架(archetype)
> mvn archetype:generate 接下来就会输出一些列带索引变化的archetype项可供我们选择,然后提示我们选择一个编号,可以直接回车选择默认的编号(392),然后就跟着 ...
- 机器人研发十大热门编程语言:不死 Java、不朽 C/C ++、新贵 Python
流水的编程语言,铁打的 Java.C/C++. 进行人工智能机器人研发,应该选择哪种编程语言? 这是很多机器人专家在自身的职业生涯中都会存在的一个入门级思考.毕竟,在学习一门编程语言时,需要花费大量的 ...
- LSTM与Highway-LSTM算法实现的研究概述
LSTM与Highway-LSTM算法实现的研究概述 zoerywzhou@gmail.com http://www.cnblogs.com/swje/ 作者:Zhouwan 2015-12-22 ...
- 天气预报APP(1)
一个天气预报APP至少应该具备以下功能: *可以罗列出全国所有的省.市.县: *可以查看全国任意城市的天气信息: *可以自由的切换城市,去查看其他城市的天气: *提供手动更新以及后台自动更新天气的功能 ...
- 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 ...
- scrapydWeb安装和使用
1. 安装:pip install scrapydweb 2. 启动:scrapydweb 第一次执行,当前目录会生产配置文件:scrapydweb_settings_v8.py 配置账户和密码: # ...
随机推荐
- list集合根据字段分组统计转换成map
前言 表格需要对数据进行统计 代码实现 public Map getUnitStoreSum(String unitId, String billCode) { List store=listUnit ...
- Python+requests环境搭建和GET基本用法
Python+requests环境搭建 首先你得安装Python,然后安装requests模块(第3方模块,安装方法:pip install requests) 基本用法 get 请求(不带参数的) ...
- VirtualBox设置双网卡实现主宿互访及虚拟机访问互联网总结
1,配置网络 注:VirtualBox要在全局工具-主机网络管理器里新建一个虚拟网卡. 然后虚拟机的网卡1设置为host-only,界面名称为新建的虚拟网卡(我这里为了不跟主机ip冲突,设置成了不同网 ...
- 迁移appseting.json创建自定义配置中心
创建一个自定义的配置中心,将框架中各类配置,迁移至数据库,支持切换数据库,热重载. 说在前面的话 自使用.net Core框架以来,配置大多存在json文件中: [框架默认加载配置]文件为appset ...
- React Native之新架构中的Turbo Module实现原理分析
有段时间没更新博客了,之前计划由浅到深.从应用到原理,更新一些RN的相关博客.之前陆续的更新了6篇RN应用的相关博客(传送门),后边因时间问题没有继续更新.主要是平时空余时间都用来帮着带娃了,不过还是 ...
- CF992E Nastya and King-Shamans(线段树二分+思维)
这是一道卡常好题 从160s卡到36s qwq 由于题目设计到原数组的单点修改,那么就对应着前缀和数组上的区间加. 很显然能想到用线段树来维护这么个东西. 那么该如果求题目要求的位置呢 我们来看这个题 ...
- 【HMS Core 6.0全球上线】华为钥匙环服务,打造跨应用跨形态无缝登录体验
华为钥匙环服务(Keyring),是HMS Core在安全领域开放的全新服务,为全球开发者提供用户认证凭据(以下简称"凭据")本地存储和跨应用.跨形态共享能力,帮助您在安卓应用.快 ...
- Stream中的Collector收集器原理
前言 Stream的基本操作因为平时工作中用得非常多(也能看到一些同事把Stream操作写得很丑陋),所以基本用法就不写文章记录了. 之所以能把Stream的操作写得很丑陋,完全是因为Stream底层 ...
- 「刷题」THUPC泛做
刷了一下,写一下. T1. 天天爱射击 可以这样想. 我们二分一下每一块木板在什么时刻被击碎. 然后直接用主席树维护的话是\(O(nlog^2n)\)的. 会\(T\),而且是一分不给那种... 那么 ...
- AGC019F
题目大意 $n$ + $m$ 个问题,其中$n$ 个答案是$YES$,$m$个是$NO$的,你依次答题,每答一道,就可以立刻知道这道题的答案,求在最优策略下答错次数的期望,对$998244353$取模 ...