發表文章

目前顯示的是 11月, 2020的文章

Select & SelectMany 的差異為何?

資料來源: https://social.msdn.microsoft.com/Forums/vstudio/en-US/ebf4adac-8873-44f1-9def-a10912e4d2ef/what-is-the-difference-between-select-and-selectmany?forum=adodotnetentityframework   Select operator is used to select value from a collection and SelectMany operator is used to select values from a collection of collection i.e. nested collection. select 通常用於取得集合中的值,可能是單一值或另一個集合 selectmany 則用於取得集合中集合的值,不是想像中查詢多個欄位的用法,因為回傳多個欄位用的是 tuple value or anonymous type這兩種方式。 回到主題,selectmany的好處在於可以直接取得巢狀集合(集合中有另一集合)中的值,讓迴圈少跑1次。 //寫法2 :總算看懂了, 因為 select 裡再包 1個select , 回傳後會變IEnumerable<IEnumerable<string>> //如果是 selectmany 裡再包 1個select , 回傳時變成 IEnumerable<string> , 讓你少寫1次迴圈 var customerOrders_Tuple = customers.SelectMany( //SelectMany 簡化為單一序列 , 跑1次迴圈就能抓出值 .  (cust, custIndex) => cust.Orders.Select(o => "Customer #" + (custIndex + 1) + " has an order with OrderID " + o.OrderID)); foreach (var order in customerOrders_Tuple) { Console.WriteLine(order); } Wri...

Select with index of item(分別取得"列表值" & "列表索引")

 //Select with index of item(分別取得"列表值" & "列表索引")         static void Select_With_Index_of_item()         {             int[] numbers = { 6, 4, 3, 9, 8, 5, 7, 2, 0 }; //var numsInPlace = numbers.Select((num, index) =>  (Num: num, InPlace: (num == index)));  //元組tuple寫法,只有C#7可以用 var numsInPlace = numbers.Select((num, index) => new { Num = num, InPlace = (num == index) } );  //匿名anonymous寫法,C#6可以用             foreach (var item in numsInPlace)             {                 WriteLine($"{item.Num} : {item.InPlace}");             }         }

載入JavaScript code的最佳時機

 To summarize: async and defer both instruct the browser to download the script(s) in a separate thread, while the rest of the page (the DOM, etc.) is downloading, so the page loading is not blocked by the scripts. If your scripts should be run immediately and they don't have any dependencies, then use async. If your scripts need to wait for parsing and depend on other scripts and/or the DOM being in place, load them using defer and put their corresponding <script> elements in the order you want the browser to execute them.

LINQ學習重點(SELECT 1)

 //Select a subset of properties         static void Ex7()         {             List<Product> products = GetProductList();             var productInfos = from p in products                                select new { p.ProductName , Price = p.UnitPrice};             foreach (var item in productInfos)             {                 Console.WriteLine($"{item.ProductName} is and costs {item.Price} per unit.");             }         }         static void Ex7_Tuple() //元組寫法         {             List<Product> products = GetProductList();             //v...

[SOLVED] .NetFrameWork 4.5.2 不支援 C#7.0 語法,所以裝了 System.ValueTuple 套用也沒有用

因為公司開發環境是 4.5.2,不是4.7.2,為了避免亂裝一些東西,造成 寫好的程式掛掉。 就決定不升級至 4.7.2,也先不用元組型別(System.ValueTuple)練習 LINQ。 OK。

在匿名 anonymous type 和元組 tuple type 類型之間選擇

圖片
  在匿名和元組類型之間選擇 2020/07/01   選擇適當的類型牽涉到考慮其可用性、效能和取捨,相較于其他類型。   自 c # 3.0 起已提供匿名型別,但  System.Tuple<T1,T2>  .NET Framework 4.0 引進了泛型型別。   自從起,新選項在語言層級支援上引進,像是  System.ValueTuple<T1,T2>  名稱所暗示的,提供具有匿名型別彈性的實值型別。   在本文中,您將瞭解何時適合選擇另一種類型。 結論 當開發人員在元組和匿名型別之間進行選擇時,需要考慮幾個因素。   一般來說,如果您不是使用  運算式樹狀 架構,而且您熟悉元組語法,則請選擇  ValueTuple  其提供實值型別,而且可以彈性地命名屬性。   如果您是使用運算式樹狀架構,而且想要命名屬性,請選擇 [匿名型別]。   否則,使用  Tuple 。 資料來源:https://docs.microsoft.com/zh-tw/dotnet/standard/base-types/choosing-between-anonymous-and-tuple

LINQ學習重點(WHERE)

  Restriction operators : The  where  keyword The  where  keyword or  Where  method provide this capability. These operators restrict, or filter, the input sequence to produce an output sequence. Your first query : the structure of a LINQ query. Filter elements on a property : filter elements based on a single property Filter elements using multiple properties : test multiple properties to filter elements in a sequence. Filter and drilldown into the output elements : filter input elements, then drill into a sequence on each output element. Filter input elements based on index : use an element's position to filter it. //Filter elements based on position(這種寫法,第1次看)         static void Ex4()         {             string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };             var shortDigits = digits.Where((...

插補字串,指定日期格式

 static void Ex3()         {             var customers = GetCustomerList();             var tpeCustomers = from cus in customers                                where cus.Region == "TPE"                                select cus;             WriteLine("==Query Result==");             foreach (var item in tpeCustomers)             {                 WriteLine($" Customer<{item.CustomerID}> : {item.CompanyName}");                 foreach (var order in item.Orders)                 {                 ...

北商資管系-夜二技讀書計劃

北商讀書計劃(行動數位服務模組): 洽詢電話: 平日上、下午(02)2322-6050、6053、6048~49 平日晚間(02)2322-6235 通識科目: 10 學分 專業必修: 72(畢業最低學分數) - 10 - 36 = 26學分(一門課都不能少) =(一上)=     1. 程式設計(3)     2. 管理資訊系統(3) <= 企業e化模組     3. 資訊倫理與法律(2) =(一下)=     4. 應用統計學(3)    # 詢問是否可折抵學分     5. 物件導向系統分析與設計(3)     6. 資訊網路(3) =(二上)=     7. 電子商務與網路行銷(3) <= 企業e化模組     8. 資料庫管理(3) <=行動數位服務模組 =(二下)=     9. 行動商務應用(3) <= 行動數位服務模組 專業選修:13 * 3 = 39 (至少應修 36 學分) =(一上)=     1. 資料結構(3)     2. 網站應用程式設計(3) <= 行動數位服務模組     3. 資料探勘與大數據分析(3) <= 企業e化模組 =(一下)=     1. 行動應用開發(3) <= 行動數位服務模組     2. 國際認證管理(3) =(二上)=     1. 國際認證管理進階(3)     2. 行動應用程式設計(3)     3. 演算法(3)     4. 伺服器架設與規劃(3)     5. 資訊安全(3) =(二下)=     1. 商業智慧與資料科學(3)     2. 資料庫管理系統實作(3)     3. 密碼學(3)

SOP-C#資料結構-筆記

========= C#資料結構(參考書目:資料結構使用Visual C#。ISBN:978-986-500-413-2)   CH4-鏈結串列     類別,物件及成員(屬性,方法)       1.public 公開 所有類別皆可存取       2.private 私有 只適用該類別的成員函數       3.protected 保護 產生繼承關係的衍生類別可取用       4.internal 內部 只適用於目前專案(組件)       5.protected internal 只適用於目前(組件)或衍生自包含類別的型別          建構子       1. 語法:ClassName() ex. Student()       2. 建構子存取修飾詞必須使用 public       3. 一個類別可以有多個建構子(又稱多載),它不能有回傳值,也毋須用void       4. 類別若不含任何具參數建構子時,程式自動呼叫<預設建構函式>     解構子       1. 語法:~ClassName() ex. ~Student()       2. 解構子不能使用存取修飾詞       3. 一個類別只能有1個解構子,它不含任何參數,不能有回傳值,無法被繼承或多載       4. 解構子無法直接呼叫,只有物件被清除時才會執行     環狀串列       1.它和單向鏈結串列相似,不同點在於必須將 (最後1個節點) 指向 (第1個節點)       2.優:           回收時間固定,無關長度     ...

C# 6.0語法調整(匯入靜態類別及字串插補)

匯入靜態類別 原: using System; Console.WriteLine(); 新: using System; using static System.Console; //改變在這裡 WriteLine(); //直接指定方法,少寫一次類別名稱 字串插補 原:WriteLine("Hello {0} ",name) ;  新:WriteLine($"Hello {name}") ; //不用再排順序,直接將變數塞進去

VSCode 建立DEBUG設定

 按下F5,會提示你設定 "launch.json" 內容。 設定後,再次按下F5,VSCode就會執行,很方便的。 {      // Use IntelliSense to learn about possible attributes.      // Hover to view descriptions of existing attributes.      // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387      "version" :  "0.2.0" ,      "configurations" : [         {              "name" :  "Launch Edge(file)" ,              "request" :  "launch" ,              "type" :  "pwa-msedge" ,              "file" :  "${workspaceFo...

LINQ哪種查詢語法比較好?

 原則上,兩種都要會。 擴充方法格式(.符號語法) 查詢表達式(推用法,尤其是群組與聯結),比較好懂 擴充方法+查詢表達式(作者傾向先用查詢表達式,再併用擴充方法) 因為作者有SQL背景,所以才會有上述建議(先用查詢表達式,除非不支援,才會加用擴充方法)。 還有另一個考量點,程式碼除了寫給自己看以外,還要讓外人看的懂。 int []  numsCombine  =  new   int []{ 0 , 5 , 1 , 9 , 2 , 6 , 3 , 10 , 1 , 1 , 1 , 3 , 4 };              var   result4  = ( from   n   in   numsCombine                            where   n  <  5                            orderby   n                            select   n ). Distinct (); //這裡就是兩種併用

超開心,完成第1個List實作。

最近剛到一家新的產險公司上班,企圖將以往落後許多的程式開發能力拉一點回來。

第一篇blog

 第一篇blog