C#從零開始_自學C#、Visual Studio實境秀 38/ C#7.0新功能介紹、Getting Started with C# Less...



{

Code Review Guidance 1:20:00 http://bit.ly/2uUs5AT

程式一定有bug主要是因為開發人員很容易陷入自己的盲點,常見的盲點有兩種:

程式是照你寫的跑,不是照你想的跑。

程式照你想的跑,但你想的是錯的。

要突破上述的盲點,最簡單的方式就是找別人來review你開發中或開發完的程式,跟你一起確認程式是否寫的跟你想的一樣,以及確認你想的是對的。

1:43:00 看吧 還不是要回歸人性面嗎? 倫理道德教育沒必要、聖賢教育不重要?

1:44:50 這不就是「遍法界虛空界盡此一法身嗎?」十方三世佛,共同一法身嗎?

1:30:00 Repository Pattern 多來源、多元資料來源的處理 http://bit.ly/2tqIh8h



1:36:00 使用資料剖析精靈將文字分割成不同的欄 https://support.office.com/zh-hk/article/%E4%BD%BF%E7%94%A8%E8%B3%87%E6%96%99%E5%89%96%E6%9E%90%E7%B2%BE%E9%9D%88%E5%B0%87%E6%96%87%E5%AD%97%E5%88%86%E5%89%B2%E6%88%90%E4%B8%8D%E5%90%8C%E7%9A%84%E6%AC%84-30b14928-5550-41f5-97ca-7a3e9c363ed7

您可以將一或多個儲存格中的文字分散到多個儲存格中。這就是所謂的剖析 (與串連相反),其中您可以將兩個或兩個以上的儲存格之文字合併成一個儲存格。例如,……



2:00:00 2:21:00 動態陣列初始化的判斷



2:28:40 C# 7.0 新功能介紹 http://bit.ly/2uUwmnO

{

2:42:00 Tuples, 能讓你更容易的一次傳回多筆結果,

希望所有的這些改變都能讓你更愉快的寫出有效率,簡潔的程式碼,同時也更有生產力。

6:48:00 C# 7.0 新功能 out pattern 就是將變數宣告合併到 expression 裡頭,簡化程式碼,就很類似 Expression Bodied member 的概念

6:50:00 在 C# 7.0,我們也擴大了 switch 陳述式的應用範圍:

switch 陳述式現在可以運用在所有型別 (不再只限於基本類型)

patterns 可以用在 case 子句

case 子句可以附加條件判斷式  要和 when 關鍵字一起使用 http://bit.ly/2tsH6Fw

case 子句的順序是重要的:

就如同 catch 子句一樣,多個 case 子句之間不再是沒有順序關聯的,而第一個符合條件的 case 子句會被選中。這點非常重要

7:04:30 Tuples

想要從一個 method 傳回一個以上的傳回值是蠻常見的狀況

為了讓這件事做得更好,C# 7.0 新增了 tuple types 及 tuple literals 的語法:

(string, string, string) LookupName(long id) // tuple return type

{

... // retrieve first, middle and last from data storage

return (first, middle, last); // tuple literal

} 這 method 現在能更有效率的傳回三個字串型別的傳回值了,這範例將三個字串包成一個 tuple。

呼叫這 method 的程式碼將會收到回傳的 tuple 物件,且能透過 tuple 物件個別存取這些封裝在內的資料:

7:21:00 另一個使用 tuples 的方式是將他們 deconstruct (解構)。Deconstructing declaration (解構宣告) 是用來將 tuple (或是其他值) 裡面的部分拆解並個別指派到其他新的變數用的語法:

7:23:00 都是為了簡化程式碼嘛

7:32:00 Local functions (區域函式) 你可以在其他函式內宣告 local functions (區域函式): 恐怕類似子程序的概念 方法裡頭的方法、函式裡頭的函式 可稱子函數或子函式

7:40:30 C# 7.0 允許在 number literal (數字常數) 中,用 _ 當作 digit separator (數字分隔器):

var d = 123_456;

var x = 0xAB_CD_EF;

你可以將 _ 放在數字中的任何位置,來提高程式碼的可讀性,完全不會對數值本身有任何影響。

都是為了簡化或可讀性、人性化(編程效率提昇)

C# 7.0 也引入二進位的常數表示方式,你現在可以直接用二進位的方式來取代過去十六進位 (例: 0x001234) 的表示方式。例如:

var b = 0b1010_1011_1100_1101_1110_1111;

7:44:00 Ref returns 與 ref locals 如同你可以在 C# 用參考的方式傳遞參數 (使用 ref 修飾詞),你現在也可以用同樣的方式將區域變數的數值用參考的方式傳回。

這在回傳大型資料結構時相當有用。

7:53:30 ref locals 在初始化時會被指向某個儲存位置,一旦指派之後無法再更改。

7:54:10 非同步的傳回型別 C# 7.0 開始,也允許你用同樣的方式,從非同步方法傳回你定義的其他型別。

7:56:50 更廣泛的 expression bodies 成員

8:01:30 Throw 運算式



4:53:40

字串處理

{ 5:11:00 String 在 C# 或 .net 中確實是當作陣列或集合來看待: http://bit.ly/2uw4SED

[] 運算子可以用於唯讀存取 string 的個別字元:

string str = "test";

char x = str[2];  // x = 's';

5:32:40

System.Text.StringBuilder sb = new System.Text.StringBuilder();

// Create a string composed of numbers 0 - 9

for (int i = 0; i < 10; i++)

{

sb.Append(i.ToString());

}

5:14:00 string (C# 參考)

逐字字串常值的開頭是 @,也會使用雙引號括住。 例如:

@"good morning"  // a string literal

逐字字串的優點是「不」會處理逸出序列,例如,這可讓您輕鬆地撰寫完整檔案名稱︰

若要在 @-quoted 字串中包含雙引號,請使用兩個雙引號︰

5:17:15 字串 (C# 程式設計手冊) http://bit.ly/2uLU3xX

5:41:00 字串是類型 String 的物件,其值為文字。

就內部而言,文字會儲存為 Char 物件的循序唯讀集合。 C# 字串的結尾沒有終止的 Null 字元,因此 C# 字串可以包含任何數目的內嵌 Null 字元 ('\0')。 字串的 Length 屬性代表它包含的 Char 物件數目,而非 Unicode 字元的數目。 若要存取字串中的個別 Unicode 字碼指標,請使用 StringInfo 物件。

字碼指標(應即 code point 碼位、碼點)

5:44:44 在 C# 中,string 關鍵字是 String 的別名。 因此 String 和 string 為相等,而您可以使用您偏好的命名慣例。

5:48:00 逸出代碼 \udddd (其中 dddd 是四位數字) 代表 Unicode 字元 U+dddd。 也會辨識八位數 Unicode 逸出代碼︰\Udddddddd。

5:56:10 因為對字串的「修改」實際上是建立新的字串,當您建立對字串的參考時,必須特別謹慎。

5:59:30  如需如何建立以修改為基礎 (例如原始字串上的搜尋與取代作業) 之新字串的詳細資訊,請參閱如何:修改字串內容。

6:01:20 \r\n 如 word 裡的 Paragraph 而 \n 則只是 Line

6:04:20 因為逐字字串會將新行字元保留為字串文字的一部分,因此可以將它們用來初始化多行字串。 所以換行也會照印出來。所以逐字字串,逐字便是按照字面,一個不漏,如實照實讀取也。



字串逸出序列:\n 換行 \r 歸位字元 \u Unicode 逸出序列 \U Surrogate 字組的 Unicode 逸出序列。 \t 水平 Tab

5:19:00 格式字串

格式字串是可在執行階段動態決定其內容的字串。 您可以透過使用靜態 Format 方法,並以大括號內嵌將於執行階段由其他值取代的預留位置,來建立格式字串。

s = System.String.Format("{0} times {1} = {2}", i, j, (i * j));

如需格式字串的詳細資訊,請參閱格式化類型。

5:21:15 子字串是包含在字串中的任何字元序列。 使用 Substring 方法,來從原始字串的一部分建立新的字串。 您可以使用 IndexOf 方法,來搜尋子字串的一或多個出現位置。 使用 Replace 方法,來以新字串取代所有指定的子字串。 和 Substring 方法類似,Replace 實際上會傳回新的字串,而不會修改原始字串。

如需詳細資訊,請參閱如何︰使用字串方法搜尋字串以及如何︰修改字串內容。

5:22:30 存取個別字元

您可以搭配索引值使用陣列標記法來取得個別字元的唯讀存取權

5:23:40 倒序字串、反序字串

5:24:25 如果 String 方法不提供修改字串中個別字元的必要功能,您可以使用 StringBuilder 物件「就地」修改個別字元,然後使用 StringBuilder 方法建立新的字串來儲存結果。

5:27:00 Null 字串和空字串

5:30:15 使用 StringBuilder 進行快速字串建立

.NET 中的字串作業已高度最佳化,在大部分的情況下不會大幅影響效能。 不過,在部分案例中 (例如執行數百或數千次的緊密迴圈),字串作業可能會影響效能。 StringBuilder 類別會建立一個字串緩衝區,能在您的程式執行許多字串操作的情況下提供較佳的效能。 StringBuilder 字串也可讓您重新指派個別字元,這是內建字串資料類型所不支援的。

5:35:00

字串、擴充方法和 LINQ

因為 String 類型會實作 IEnumerable<T>,您可以在字串上使用 Enumerable 類別中定義的擴充方法。 為了避免視覺雜亂,這些方法會從 String 類型的 IntelliSense 中排除,不過您還是可以使用它們。

您也可以在字串上使用 LINQ 查詢運算式。 如需詳細資訊,請參閱 LINQ 和字串。

5:39:10

// Use the String constructor only when creating

// a string from a char*, char[], or sbyte*. See

// System.String documentation for details.

char[] letters = { 'A', 'B', 'C' };

string alphabet = new string(letters);

除了使用字元陣列初始化字串以外,您不能使用 new 運算子建立字串物件。

使用 Empty 常數值初始化字串,以建立字串長度為零的新 String 物件。 零長度字串的字串常值表示法是 ""。 透過使用 Empty 值 (而非 null) 來初始化字串,可以減少發生 NullReferenceException 的機會。 在您嘗試存取字串之前,請使用靜態 IsNullOrEmpty(String) 方法來驗證該字串的值。

5:40:50 字串物件的不變性

字串物件為「不可變」:它們在建立之後將無法變更。 所有看似會修改字串的 String 方法和 C# 運算子,實際上會以新的字串物件傳回結果。



如何:修改字串內容 提供說明如何修改字串內容的程式碼範例。

如何:串連多個字串 說明如何使用 + 運算子和 Stringbuilder 類別,在編譯時期和執行階段聯結字串。

如何:比較字串 示範如何執行字串的循序比較。

如何:使用 String.Split 剖析字串 包含說明如何使用 String.Split 方法剖析字串的程式碼範例。

如何:使用字串方法搜尋字串 說明如何使用特定方法來搜尋字串。

如何:使用規則運算式搜尋字串 說明如何使用規則運算式來搜尋字串。

如何:判斷字串是否表示數值 (C# 程式設計手冊) 示範如何安全地剖析字串,以查看它是否有有效的數值。

{ 6:27:20 使用靜態 TryParse 方法 http://bit.ly/2vMPWyE

一律使用 TryParse 或 Parse 方法驗證控制項的使用者輸入,例如文字方塊和下拉式方塊。

}

如何:將字串轉換為 DateTime 示範如何將類似 "01/24/2008" 的字串轉換為 System.DateTime 物件。

基本字串作業 提供使用 System.String 和 System.Text.StringBuilder 方法來執行基本字串作業的主題連結。

剖析字串 描述如何將字元或空格插入字串中。

比較字串 包含如何比較字串的相關資訊,並提供以 C# 和 Visual Basic 撰寫的範例。

使用 StringBuilder 類別 描述如何使用 StringBuilder 類別來建立及修改動態字串物件。

LINQ 和字串 提供如何使用 LINQ 查詢來執行各種字串作業的相關資訊。



6:12:30 LINQ 和字串 (C#)

{http://bit.ly/2tqQ8mn http://t.cn/RKkV9ya

6:14:30 文字分離器:您可以使用 Split 或 Split 方法建立字串陣列,以利用 LINQ 查詢或修改。

Regex.​Split Method 6:20:00

Regex.​Split Method

6:20:40 如何:統計某個字在字串中出現的次數 (LINQ) (C#)  字頻詞頻調查

6:20:00 LINQ 查詢也簡化了多種來源資料的結合工作。

如何:尋找兩個清單之間的集合差異 (LINQ) (C#)

如何:依任何字或欄位排序或篩選文字資料 (LINQ) (C#)

如何:合併和比較字串集合 (LINQ) (C#)

如何:從多個來源填入物件集合 (LINQ) (C#)

示範如何將多個文字檔案作為資料來源以建立物件集合。

如何:從不同的檔案聯結內容 (LINQ) (C#)

示範如何使用相符的索引鍵,將兩份清單中的字串結合為單一字串。

如何:使用群組將檔案分割成許多檔案 (LINQ) (C#)

示範如何將單一檔案作為資料來源以建立新的檔案。

Language-Integrated Query (LINQ) (C#) http://bit.ly/2gTSZT8



System.Text.RegularExpressions (規則運算式)

System.Text.StringBuilder

6:17:50 將半結構化的文字資料轉換成 XML。 如需詳細資訊,請參閱如何:從 CSV 檔案產生 XML。

}



5:51:00 Basic String Operations in .NET http://bit.ly/2umOhlB

{Several methods in the System.String and System.Text.StringBuilder classes allow you to dynamically construct custom strings to display in your user interface.

6:42:10 creating new strings from arrays of bytes 從二進位陣列轉換成文字字串

Creating New Strings

Describes basic ways to convert objects into strings and to combine strings.

Trimming and Removing Characters

Describes how to trim or remove characters in a string.

Padding Strings

Describes how to insert characters or empty spaces into a string.

Comparing Strings

Describes how to compare the contents of two or more strings.

Changing Case

Describes how to change the case of characters within a string.

Using the StringBuilder Class

Describes how to create and modify dynamic string objects with the StringBuilder class.

How to: Perform Basic String Manipulations

Demonstrates the use of basic string operations.

}

}



}



3:00:00 3:42:00 加入 GitHub

{GitHub 其實就是線上開源協作程式碼 Project showcases 則是激發人用程式解決問題、實現夢想。 https://github.com/explore

https://guides.github.com/

4:25:00 在 Github 啟建第一個 repository project : CJK-Unified-Ideographs-Unicode-Characters-Handlers

}



8:10:00  Getting Started with C# Lesson 1 of 20

Creating a Hello World Program http://bit.ly/2vxUQQY

{

commands 即一個 statement 一行指令、一行程式碼

 Its file extension is "cs" because it contains C# source code.

build 建置

8:17:30 What's a namespace? A namespace is a way of organizing programming constructs.

They're similar to folders or directories in your file system.

分號 In C#, most statements that aren't defining a scope end with a semicolon.

8:26:00 Namespaces are optional;  不必具名命名空間

8:26:40 所以 scope就翻成「結界」就很好 scope (defined by its curly braces) Accessibility Domain (C# Reference) 也類似

8:29:00 Accessibility Levels (C# Reference) Access modifiers are not allowed on namespaces. Namespaces have no access restrictions. http://bit.ly/2uN0W26

a default accessibility is used.

Top-level types, which are not nested in other types, can only have internal or public accessibility. The default accessibility for these types is internal.

8:33:00 enum interface 一定都是 public

8:41:00 the static keyword marks this method as global and associated with the type it's defined on, not a particular instance of that type.

8:45:00 Arguments correspond to parameters. A method defines the parameters it requires; when calling a method, the values passed to its parameters are referred to as arguments.

8:52:45 A string is a series of text characters.

}

9:00:55 Lesson 2 of 20 http://bit.ly/2gTUL6S Learning About Built-In Types and Variables

{

var, which you can think of as variable

9:06:10 The // on the line represents a single-line comment.

9:14:00 Within Visual Studio, ctrl+F5 will run the console application, launching a new console window.

ctrl+F5 其實是讓 console window 不會自己關閉,如同加了 Console.ReadKey() 一樣

}

9:17:10 Lesson 3 of 20 Working with Strings 字串處理 http://bit.ly/2tr7tf0

{

9:21:50 When a string is instantiated in C#, a sequence of bytes in memory is allocated to it.

This allocation cannot be modified after-the-fact; it can only be erased once the string is no longer in use by the program.

9:26:00 斷句、找對主詞(代名詞代誰,很重要) 九陽神功第一招、第八招!

9:31:00 Strings are reference types, which means (among other things) they are null when they are declared, until they are assigned a value.

9:31:50 statement= command

9:35:50 String.Empty is a built-in constant value for a string with zero length.

9:38:00 It's important to understand the difference between an empty string and a null string (or other reference type).

9:40:00 對 null 的認識 :Take care when working with nulls in your programs, especially if they may be passed to other methods, and be sure to confirm that arguments your methods work with are not null before working with their members.

null 有點像中文罵人:你什麼都不是

9:42:20 先抓動詞、找對主詞 九陽神功七、八聯招

9:43:20 拿讀古文 文言 的功夫來讀英文。

9:49:00 Null values are frequent sources of bugs even for experienced programmers.  人有失手,馬有亂蹄

}

}


留言

熱門文章