WebClient wc = new WebClient(); //
MemoryStream ms = new MemoryStream(wc.DownloadData(RSS_Source.Address));
XDocument doc = XDocument.Load(ms);
var query = (from feed in doc.Descendants("item")
select new
{
Title = feed.Element("title").Value,
Description = feed.Element("description").Value,
Date = DateTime.Parse(feed.Element("pubDate").Value),
link = feed.Element("link").Value,
testImage = feed.Elements("image").ToArray()
}).ToArray();
List 的方法
增加項目
void ListObject.Add(item);
檢查是否包含在List裡面
boolean ListObject.Contains(item);
直接創建一個新的相同內容的List物件
List<T> NewList = new ListObject.ToList();
字串切割
string str = "hello[myfriend]";
int indexS = 0;
int indexE = 0;
indexS = str.IndexOf("[");
indexE = str.IndexOf("]");
Console.WriteLine(str.Substring(indexS+1,indexE-indexS-1));
//myfriend
假如字串都有規律
str = str.Replace("hello[","").Replace("]","");
也可以得到相同效果
URL解析
判斷物件是否為null
boolean Object.Equals(obj1,obj2);
obj2 放 null
obj1 放想要測試的物件即可
判斷字串為空或者null
boolean string.IsNullOrEmpty(str)
開執行緒去呼叫外部程式
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "檔案路徑";
p.StartInfo.Arguments = 參數1 + " " + 參數2;
p.StartInfo.UseShellExecute = false;
p.Start();