ken 20150306 心得分享
TRANSCRIPT
心得分享
李佳駿
委派 delegate
使用時機:可能會碰到某個方法在執行時需要額外的處理,但你不想/無法將這部份的處理寫死在類別裡(因為變化太多或無法預先得知其處理規則)
委派 delegate-1
void Main() { CarMileage(10,0).Dump(); }
public int CarMileage(int time , int cartype) { switch (cartype) { case 0: return 10 * time; case 1: return 20 * time; default : return 30 * time; } }
委派 delegate-2
void Main() { CarMileage Mileage = new CarMileage(Car0); Mileage(10).Dump(); }
public delegate int CarMileage(int time);
public int Car0(int time) { return 10 * time; }
public int Car1(int time) { return 20 * time ; }
public int CarOther(int time) { return 30 * time ; }
Using()
一些物件在執行完成後需要做 Dispose();
釋放記憶體 ,避免程式撰寫時會遺漏可以利用
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
{ // 要做的事情 }
ZipFile.OpenRead(zipPath)
number of entries expected in end of central directory does not correspond to number of entries in central directory
NuGet :DotNetZip
IEnumerable<T>
判斷有無資料請用
if (resultItem.Count() > 0)
if (resultItem.Any())
取得 XML資料
1. doc.Elements("cn-publication).Element("document-id").Value;
1. doc.Descendants().Where(u => u.Name == "country").First().Value;
SQL隱碼攻擊
using (SqlConnection conn = new SqlConnection(connstr)) {
conn.Open(); StringBuilder sqlStr = new StringBuilder( @"Select * from [Table] where ID =“ + textBox1.Text ); cmd.ExecuteNonQuery();
}
SQL隱碼攻擊 -1
using (SqlConnection conn = new SqlConnection(connstr)) {
conn.Open(); StringBuilder sqlStr = new StringBuilder( @"Select * from [Table] where ID=@ID“);
SqlCommand cmd = new SqlCommand(sqlStr.ToString(), conn);
cmd.Parameters.Add(new SqlParameter("@ ID ", textBox.Text));
cmd.ExecuteNonQuery(); }
.txt比對資料 -1
比對字串裡面是否有“ 123”這個字串
string sentence = File.ReadAllText(@"D:\log.txt");
var isContain = sentence.IndexOf("123",
StringComparison.OrdinalIgnoreCase) >= 0;
.txt比對資料 -2
string[] contents = File.ReadAllLines(@“D:\Log.txt");
return contents.Any(a => a == “123” );
return contents.All(a => a == “123”);
contents.Where( a=> a.Contains(“123"));
LINQ
命名習慣在 LINQ 文件中,儲存查詢的變數的名稱中都會包含 “query” 這個字; 如果是儲存實際結果的變數,
它們的名稱中就不會有 “ query” 這個字。
var queryCities = from city in cities where city.Population > 100000 select city;
LINQ-group
var studentQuery2 =
from student in students group student by student.Last[0]
into g orderby g.Key select g;
BCP-1
bcp "SELECT * FROM [table]” queryout %CD%\FileName.data -U username -P password -S server -N
-N :當您要傳送的資料包含 ANSI 擴充字元而且您要利用原生模式的效能時,請使用這個選項。
BCP-2
bcp [DataBase].dbo.[Table] in %CD%\FileName.data -U username -P password -S server –N
JavaScript-parseInt()
>parseInt("123", 10) 123 >parseInt("010", 10) 10
> parseInt("010") 8
> parseInt("hello", 10) NaN
> isNaN(NaN)
JavaScript-Boolean()
false 、 0 、空字串 ("") 、 NaN 、 null 、以及 undefined 都會成為 false
> Boolean(234) true
JavaScript-arguments
function add() { var sum = 0; for (var i = 0, j = arguments.length; i < j; i++) {
• sum += arguments[i]; } return sum;
}
> add(2, 3, 4, 5) 14 > add(2, 3, 4) 9
arguments.callee.count
Jquery
http://www.w3school.com.cn/tags/att_a_hreflang.asp HTML 標籤 http://jsbin.com/fayidowuce/5/edit jsbin
Jquery
<div class="OK"></div> $( ".OK" )
<div id ="OK"></div> $( "#OK" )
<div></div> $( "div" )
<div class="after-andself"> <p>First Paragraph</p> <p>Second Paragraph</p> </div> $( "div.before-andself" )
Jquery
<div class="left"></div> <div class="right"></div>
$( "div.left, div.right" )
SQL 隱碼攻擊 -1
http://huan-lin.blogspot.com/2009/01/delegate-revisited-csharp-1-to-2-to-3.html 委派 http://www.dotblogs.com.tw/smartleos/archive/2013/04/10/101297.aspx IEnumerable<T> 中有無資料,用 Any()