国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C# for Beginner session 1 to 10

2019-11-17 02:42:20
字體:
來源:轉載
供稿:網友

C# for Beginner session 1 to 10

session 1Introduction

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

session 2Reading 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 (對大小寫敏感)

session 3Built - 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

session 4String type in c#

talk about escape /n,/',/" and etc. sometimes using @ to notescape(轉義)

session 5Common Operators in c#

Assignment operator =(賦值運算符)

Arithmetic operator +,-,*,/,%

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

Conditional operator like && , ||

Ternary operator ?:

Null coalescing operator ??

session 6Nullable 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, in j = i ?? 0. it means if i is null, then j = 0 ,else ,i =j

Session 7Datatypes 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

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

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#

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()

Session 8Arrays 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.(必須依靠索引來存儲或檢索項目從數組。)

Session 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

Session 10If 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.


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永昌县| 邹平县| 香港 | 桦川县| 蓝山县| 涟源市| 宁安市| 咸阳市| 怀柔区| 西乌珠穆沁旗| 万载县| 东安县| 西丰县| 无锡市| 明光市| 山西省| 澄城县| SHOW| 宣汉县| 嘉禾县| 高安市| 麟游县| 凌海市| 蒙自县| 北碚区| 东港市| 喀喇沁旗| 海城市| 建瓯市| 蒲江县| 五指山市| 白玉县| 铜鼓县| 曲麻莱县| 乌苏市| 邵阳市| 藁城市| 福州市| 商洛市| 页游| 马尔康县|