Posts
[.NET Concept]throw V.S throw ex
namespace ConsoleApplication6 { class Program {
static void Main() { TestThrow(); TestThrowEx(); } static void ThrowException() { throw new Exception(); } static void TestThrow() { try { try { ThrowException(); } catch (Exception) { throw; } } catch (Exception ex) { Console.WriteLine("TestThrow"); Console.WriteLine(ex.StackTrace); Console.WriteLine(new string('=',50)); } } static void TestThrowEx() { try { try { ThrowException(); } catch (Exception ex) { throw ex; } } catch (Exception ex) { Console.
read morePosts
MaxToCode
-project=<projectfile> 從 MaxtoCode 項目文件中的信息開始加密 (.mcproj)
-p 參數不可以與其它參數共同使用 -out=<out directory> 加密后的程序集輸出目錄
-runtime=<Mruntime3.dll> 運行庫名稱
-bind 合并運行庫
-string 加密用戶字符串
-blob 加密用戶blob信息
-resource 加密用戶資源
-new 加密構造函數
-support64 支持64位操作系統
-autoconfusion 自動混淆當前程序集,如沒此選項都不混淆程序集
-metaconfusion 混淆原數據
-strongname=<snk file> 使用引命名簽此文件
-weboptimize 如果是Web相關程序,請帶上此參數
read morePosts
.NET 4.0 New Feature - IObservablelt;Tgt; amp; IObserverlt;Tgt;
public Unsubscriber(List<IObserver<T>> observers, IObserver<T> observer) { this.m_Observers = observers; this.m_Observer = observer; } public void Dispose() { if (m_Observer != null && m_Observers.Contains(m_Observer)) { m_Observers.Remove(m_Observer); } } }</pre> public class Observable<T> : IObservable<T> { #region Class private class Unsubscriber : IDisposable { private List<IObserver<T>> m_Observers { get; set; } private IObserver<T> m_Observer { get; set; }
public Unsubscriber(List<IObserver<T>> observers, IObserver<T> observer) { this.m_Observers = observers; this.m_Observer = observer; } public void Dispose() { if (m_Observer !
read morePosts
.NET 4.0 New Feature - Environment.Is64BitProcess amp; Environment.Is64BitOperatingSystem
namespace ConsoleApplication4 { class Program { static void Main(string[] args) { Console.WriteLine(“64位元作業系統: {0}",Environment.Is64BitOperatingSystem); Console.WriteLine(“64位元處理序: {0}”, Environment.Is64BitProcess); } } }
read morePosts
LINQ to CSV library
Read<T>(string fileName) Read<T>(string fileName, CsvFileDescription fileDescription) Read<T>(StreamReader stream) Read<T>(StreamReader stream, CsvFileDescription fileDescription)
[CsvColumn(Name = "LastName", FieldIndex = 1)] public String LastName { get; set; } [CsvColumn(Name = "Sex", FieldIndex = 2)] public String Sex { get; set; } [CsvColumn(Name = "Birthday", FieldIndex = 3)] public String Birthday { get; set; } public String Memo { get; set; } public override string ToString() { return string.Join(",", new string[] { FirstName, LastName, Sex, Birthday, Memo }); } }</pre> CsvContext cc = new CsvContext(); Person[] persons = new Person[] { new Person() { FirstName = "Larry", LastName = "Nung", Sex = "Boy", Birthday = "1980/04/19" } }; cc.
read morePosts
[C#][VB.NET]最大公因數 amp; 最小公倍數
private int LCM(int num1, int num2) { return num1 * num2 / GCD(num1, num2); }</pre></div> Private Function LCM(ByVal num1 As Integer, ByVal num2 As Integer) As Integer Return num1 * num2 / GCD(num1, num2) End Function</pre></div> namespace ConsoleApplication1 { class Program { private static int GCD(int num1, int num2) { int min = 0; int max = 0; int maxModMin = 0; min = Math.Min(num1, num2); max = Math.Max(num1, num2); maxModMin = max % min; return maxModMin > 0 ?
read morePosts
Linq To Excel Provider
using System.Linq; using System.ComponentModel;
[ExcelSheet(Name=“Sheet1”)] public class Person: INotifyPropertyChanged {
private double _id; private string _firstname; private string _lastname; private DateTime _birthdate; public event PropertyChangedEventHandler PropertyChanged; protected virtual void SendPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } [ExcelColumn(Name="ID", Storage="_id")] public double ID { get { return _id;} set { _id = value; SendPropertyChanged("ID"); } } [ExcelColumn(Name="FirstName", Storage="_firstname")] public string FirstName { get { return _firstname;} set { _firstname = value; SendPropertyChanged("FirstName"); } } [ExcelColumn(Name="LastName", Storage="_lastname")] public string LastName { get { return _lastname;} set { _lastname = value; SendPropertyChanged("LastName"); } } [ExcelColumn(Name="BirthDate", Storage="_birthdate")] public DateTime BirthDate { get { return _birthdate;} set { _birthdate = value; SendPropertyChanged("BirthDate"); } } }
read morePosts
Linq To Excel
//自己可自行加要過濾的條件,這邊只是示範 var linq = from item in excel.Worksheet(sheetName) select item; ...</pre> //這邊會取使用Sheet1的工作表內容去做查詢動作 var linq = from item in excel.Worksheet() select item; ...</pre> var linq = from item in excel.Worksheet<Blogger>(sheetName) where item.Sex==SexType.Boy select item; ...</pre> namespace ConsoleApplication1 { class Blogger { public int ID { get; set; } public String FirstName { get; set; } public String LastName { get; set; } public SexType Sex { get; set; } public int Age { get; set; } public String Blog { get; set; }
read more