// Main function
class MainFunc
{
static void Main(string[] args)
{
string[] animals = new string[] { "Koala", "Spider", "Elephant" };
wherepractice prac = new wherepractice();
// get animals of StartName is "S"
prac.detailWhere(animals);
// get amimals of StartName is "E"
prac.lambdaWhere(animals);
// as above result, but different implement.
prac.delegateImpleWhere(animals);
Console.ReadLine();
return;
}
}
// subClass
public void detailWhere(string[] animals)
{
var q = from a in animals
where a.StartsWith("S")
select a;
foreach (string s in q)
{
printString(s);
}
}
public void lambdaWhere(string[] animals)
{
var q = animals.Where(a => a.StartsWith("E"));
foreach (string s in q)
{
printString(s);
}
}
public void delegateImpleWhere(string[] animals)
{
// To utilize "delegate" to implement lambda expression "Where".
var q = animals.Where(
delegate(string a){return a.StartsWith("E");}
);
foreach (string s in q)
{
printString(s);
}
}
imagefish 發表在 痞客邦 留言(0) 人氣()
class ListInit
{
static void Main(string[] args)
{
// The demo of List Initialize Set including old declaration and new declaration(C#3.0)
// Old initialization.
List stringOld = new List();
stringOld.Add("string_1");
stringOld.Add("string_2");
// New initialization.
List stringNew = new List()
{
"string_1",
"string_2"
};
// Combine Object and List Init.
List list = new List{
new Contact{
LastName = "Alen",
DateOfBirth = new DateTime(1234,1,13)
},
new Contact{
LastName = "AlenTwo",
DateOfBirth = new DateTime(2345,1,23)
}
};
}
private class Contact
{
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
}
}
imagefish 發表在 痞客邦 留言(0) 人氣()
class Program
{
static void Main(string[] args)
{
// The demo of Object Initialize Set including old declaration and new declaration(C#3.0)
// If member access modifier isn't declared as "public", method_1 and method_2 isn't working.
// method_1
Contact contact = new Contact();
contact.LastName = "A-len";
contact.DateOfBirth = new DateTime(2012, 04, 03);
//method_2
Contact contactNew = new Contact
{
LastName = "A-len",
DateOfBirth = new DateTime(2012, 04, 03)
};
}
private class Contact
{
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
}
}
imagefish 發表在 痞客邦 留言(0) 人氣()
阿好像很久沒寫了...(搔頭)。從韓國回來以後中間經歷了短暫的軍事訓練以後就投入到Gamania的大家庭了...,然後就忙到忘記把最後兩天的部份給補齊 = =++
。趁這個228連假的空檔,機會一鼓作氣地寫完吧!!!
老實講,其實我回國以後整理影音檔和照片才想到...這個好像是不太能拍的樣子..../冏\。拍別國家的軍事設施應該會被抓起來關吧..= =+
imagefish 發表在 痞客邦 留言(0) 人氣()
StreamReader defaults to UTF-8 encoding unless specified otherwise, instead
of defaulting to the ANSI code page for the current system.
(Hint: Convert xls/xlsx file to csv file. the encoding is ANSI.)
http://msdn.microsoft.com/zh-tw/library/6aetdk20(v=vs.100).aspx
imagefish 發表在 痞客邦 留言(0) 人氣()