2017年6月27日 星期二

C#Replace 正規化



using System.Text;
usingSystem.Text.RegularExpressions;



string S= Regex.Replace(Input,@"[^A-Z,a-z]", String.Empty);

2017年6月5日 星期一

C#IEnumerable心得

IEnumerable

ICollection
定義所有非泛型集合的大小、列舉值和同步處理方法。
集合介面


IList
IList 是 ICollection 介面的子代 (Descendant),也是所有非泛型清單的基底介面。IList 實作有三類:唯讀、固定大小與變動大小。無法修改唯讀的 IList。固定大小的 IList 並不允許加入或移除元素,但允許修改現有元素。變動大小的 IList 允許加入、移除和修改項目。

有arrayList 和soft


感覺yield returen比較好

public class List
{
    //using System.Collections;
    public static IEnumerable Power(int number, int exponent)
    {
        int counter = 0;
        int result = 1;
        while (counter++ < exponent)
        {
            result = result * number;
            yield return result;
        }
    }

    static void Main()
    {
        // Display powers of 2 up to the exponent 8:
        foreach (int i in Power(2, 8))
        {
            Console.Write("{0} ", i);
        }
    }
}
/*
Output:
2 4 8 16 32 64 128 256 
*/




2017年6月1日 星期四

[C#]委派

把工作給別人做


先用委派須先宣告方法的參數列及回傳值型態的方法名稱,注意這必須跟所要指派的方法相同
先把委派寫出來
delegate void DemoDelegate(string message);


把別人的方法給委派
第1種方法.
 DemoDelegate d1 = d.DemoDelegateMethod;

第2種方法.
 DemoDelegate d2 = delegate(string message) { System.Console.WriteLine(" " + message); };


使用委派
 d1("There"); d2("is no spoon."); }

[C#]繼承心得


父要被子繼承 加上
父:
virtual
子:
override


禁止被繼承
sealed

sealed 必須跟 override 連用,因此是讓被改寫的方法不可再被改寫。

C#抽象成員心得

  • 抽象成員:只宣告,而沒有實作的成員,抽象類別的子類別必需實作所有的抽象成員

abstract:奘在class,沒有實作,只有先宣告,要被繼承
interface :奘在method ,沒有實作,只有先宣告,要被繼承

C#abstruct心得

如果class B繼承class A,而你不想要求B一定要覆寫什麼A的method,那麼class A是否宣告成abstract class都可以
如果class B繼承class A,而你不想要別人可以new A出來, 那麼class A就可以宣告成abstract class, class A裡不必宣告abstract method
如果class B繼承class A,而你想要 B一定要寫某些 A的method(有點像B實作Ix的味道),那麼class A就可以宣告成abstract class, 並宣告abstract method, 逼class B一定要寫那些method


父
class abstrate
子
override
父
interface
子
sealed