- this:代表目前類別,可以用來識別類別成員或區域變數。
- base:代表父類別,可以用來識別父類別成員或子類別成員。
2017年10月17日 星期二
2017年6月5日 星期一
C#IEnumerable心得
IEnumerable
ICollection
定義所有非泛型集合的大小、列舉值和同步處理方法。
集合介面
IList
IList 是 ICollection 介面的子代 (Descendant),也是所有非泛型清單的基底介面。IList 實作有三類:唯讀、固定大小與變動大小。無法修改唯讀的 IList。固定大小的 IList 並不允許加入或移除元素,但允許修改現有元素。變動大小的 IList 允許加入、移除和修改項目。
有arrayList 和soft
感覺yield returen比較好
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);
第2種方法.
DemoDelegate d2 = delegate(string message) { System.Console.WriteLine(" " + message); };
使用委派
d1("There"); d2("is no spoon."); }
先用委派須先宣告方法的參數列及回傳值型態的方法名稱,注意這必須跟所要指派的方法相同
先把委派寫出來
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#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
如果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
2017年5月25日 星期四
[orcale] 新方法 using Oracle.ManagedDataAccess
重要:
1.在nuget 安裝 Oracle.ManagedDataAccess
using Oracle.ManagedDataAccess
如果有已經安裝很多oracle client
2.在config 給他一個路徑
<settings>
<setting name="TNS_ADMIN" value="D:\oracle\product\11.2.0\client_1\network\admin" />
</settings>
3.在電腦右鍵內容
系統保護
進階
環境變數
系統環境變數
新增
變數名稱:TNS_ADMIN
變數值:D:\oracle\product\11.2.0\client_1\network\admin
reference:
http://blog.miniasp.com/post/2009/08/31/Solve-ASPNET-cannot-connect-Oracle-DB-using-Development-Server.aspx
http://blog.darkthread.net/post-2015-03-31-managed-odp-net.aspx
https://forums.asp.net/t/1698774.aspx ODP+NET+issue+ASP+NET+Application+on+Windows+Server+2003+R2
2017年5月17日 星期三
[C#]練習求質數
ArrayList arry2 = new ArrayList();
int a = 8;
int c = 1;
arry2.Add(1);
Begin:
for (int b = 2;b<=a;b++ )
{
if(a%b==0)
{ arry2.Add(b);
c = b * c;
a = a/b;
Label1.Text = "不是質數";
goto Begin;
}
else
{
Label1.Text = "是質數";
}
}
arry2.Add(c);
GridView2.DataSource = arry2;
GridView2.DataBind();
int a = 8;
int c = 1;
arry2.Add(1);
Begin:
for (int b = 2;b<=a;b++ )
{
if(a%b==0)
{ arry2.Add(b);
c = b * c;
a = a/b;
Label1.Text = "不是質數";
goto Begin;
}
else
{
Label1.Text = "是質數";
}
}
arry2.Add(c);
GridView2.DataSource = arry2;
GridView2.DataBind();
訂閱:
文章 (Atom)