This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//IL,區域變數,先將Delegate宣告成null,用+= | |
internal class Class1 | |
{ | |
public delegate void MyDelegate(); | |
public void MyTest() | |
{ | |
Class1.MyDelegate mydelegate = null; | |
mydelegate = (Class1.MyDelegate)Delegate.Combine(mydelegate, delegate | |
{ | |
Console.WriteLine("test"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-var 隱含型別 | |
-匿名型別 | |
-extension method | |
-yield return | |
-Enumerable<T> | |
-IEnumerable<T> | |
-Fluent Interface | |
-介面的方法會回傳自己這個介面,達到method chaining | |
-lambda | |
-匿名方法 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var list = new List<Customer>(); | |
list.Add(new Customer() { Name = "jordan", Age = 19 }); | |
list.Add(new Customer() { Name = "小章", Age = 20 }); | |
list.Add(new Customer() { Name = "盧克", Age = 34 }); | |
list.Add(new Customer() { Name = "9gy", Age = 29 }); | |
list.Add(new Customer() { Name = "小盧克", Age = 17 }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//這段程式碼,在4.0裡面會出錯,在3.5不會出錯。 | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var o = new OrderedDictionary(); | |
for (int i = 0; i < 3; i++) | |
{ | |
o.Add(i, string.Format("{0}_{1}", i.ToString(), "yahoo")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
IList<CellPhone> o = new CellPhones(); | |
o.Add(new CellPhone()); | |
Console.WriteLine("item count:{0}", o.Count.ToString()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There is a second, rarer refactoring game. | |
Identify indirection that isn't paying for itself and take it out. | |
Often this takes the form of intermediate methods that used to serve a purpose but no longer do. | |
Or it could be a component that you expected to be shared or polymorphic but turned out to be used in only one place. | |
When you find parasitic indirection, take it out. | |
Again, you will have a more valuable program, | |
not because there is more of one of the four qualities listed earlier but | |
because it costs less indirection to get the same amount from the qualities. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myCollection = this.GetMyData(); | |
var myResult = myCollection.Select(x=> x+ ","); | |
var result= new StringBuilder(); | |
foreach(var item in myResult) | |
{ | |
result.Append(item) ; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(len(xxx)>= 0) | |
{ | |
if(xxx != "offline" && xxx != "") | |
{ | |
//xxx非"offine",且xxx非"" | |
} | |
else if(xxx=="offline") | |
{ | |
//xxx為"offline" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// GrandFather 的摘要描述 | |
/// </summary> | |
public class GrandFather : System.Web.UI.Page | |
{ | |
protected virtual int GetExpireMinutes() | |
{ | |
return 480; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.dotblogs.com.tw/code6421/archive/2012/12/03/85339.aspx | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Reflection.Emit; | |
using System.Text; | |
namespace SimpleImpl |