其實這一條很好理解,就是對類名,變數名,參數名,方法名亂寫,這樣很容易搞錯比方說起一些名字叫a1,a2就比較難以理解 應該起一些更加具有描述性,更助於理解的名字 範例程式碼:舊代碼Code public class Person { public string FN { get; set; } public decimal ClcHrlyPR() { // code to calculate hourly payrate
反射的補充載入程式集,擷取各種item代碼很明確,直接上了using System;using System.Collections.Generic;using System.Text;using System.Reflection;namespace FanShe{ public class Test { Assembly myAssembly=null; public Test() { //第一種方法:
之前有說過盡量少用繼承 這個方法就是講這個的 舊的代碼: Code public class Sanitation { public string WashHands() { return "Cleaned!"; } } public class Child : Sanitation { } 重構後的代碼: Code public class Sanitation {
Emit就是快啊,我有做測試30000條資料,直接發射的話7秒多,Emit1.2秒左右先記下來,有空了研究public static class NewClas { public static List<T> ToList<T>(DataTable dt) { List<T> list = new List<T>(); if (dt ==
Set ExcelApp = CreateObject("Excel.Application") Set ExcelSheet = createobject("Excel.Sheet") ExcelSheet.ActiveSheet.Cells(1,1).Value = "My Vbscript" ExcelSheet.SaveAs("C:\111.XLS") ExcelSheet.Application.Quit() 將這些代碼複製到記事本中,然後另存新檔所有檔案,檔案名稱叫1.vbs
這個重構方法其實就是說把類的介面抽取出來,參數傳遞的時候以介面而不是具體的類個人理解這就是面向介面的編程思想吧,有哪位達人知道的請告知一下 例子很簡單,舊代碼:Codepublic class ClassRegistration{public void Create(){// create registration code}public void Transfer(){// class transfer code}public decimal Total { get; private set;
好久沒有用多線程了,好多都忘記了記一下帶object參數的ParameterizedThreadStart:public void Start(){ for (int index = 0; index < 10; index++) { #region -- 準備參數 -- List<int> list = new List<int>(); for (int param = index; param
今天的重構很有意思,舊的代碼是根據參數State來調用三個不同的方法,擷取三個地方的裝運量代碼如下:Code public class ClientCode { public decimal CalculateShipping() { ShippingInfo shippingInfo = new ShippingInfo(); return
對集合進行封裝,只把需要的介面暴露給外部使用者,例如AddStudent,RemoveStudent以及屬性Count而不是把整個集合暴露出來讓外部使用者去操作 Codepublic class MyCollection{public MyCollection(){list = new List<StudentInfo>();}private List<StudentInfo> list = null;public void
我覺得這個其實沒什麼就是說把某些方法移動到常用的類裡面去這個應該在我們寫程式的時候潛意識裡面就會做到的例子如下 錯誤的代碼: Code public class BankAccount { public BankAccount(int accountAge, int creditScore, AccountInterest accountInterest) { AccountAge = accountAge;