Below you will find pages that utilize the taxonomy term “.NET Concept”
Posts
[.Net concept]使用方法與屬性時適時為其值做快取
//Calculate count.... ... return count; }
int count = myObj.Count; for (int i = 0; i < count; ++i) { for (int j = 0; j < count; ++j) ... } }
read morePosts
[.Net Concept]理解事件的宣告方式與用法
#region Event event NameChangingEventHandler NameChanging; event NameChangedEventHandler NameChanged; #endregion</pre> #region Event event EventHandler<FriendEventArgs> FriendAdded; #endregion
#region Protected Method protected void OnFriendAdded(FriendEventArgs e) { if (FriendAdded == null) return; FriendAdded(this, e); } #endregion
#region Public Method public void AddFriend(Person friend) { Friends.Add(friend); OnFriendAdded(new FriendEventArgs(friend.Name)); } #endregion
…
class FriendEventArgs : EventArgs { #region Var private String _name; #endregion
#region Property public String Name { get { if (_name == null) return String.
read morePosts
[.Net Concept]理解並善用String pool
Console.WriteLine(string.Format("ReferenceEquals(str1, str2) = {0}", ReferenceEquals(str1, str2))); Console.WriteLine(string.Format("ReferenceEquals(str1, str3) = {0}", ReferenceEquals(str1, str3))); Console.WriteLine(string.Format("ReferenceEquals(str1, str4) = {0}", ReferenceEquals(str1, str4))); </pre></div> Console.WriteLine(string.Format("ReferenceEquals(str1, str2) = {0}", ReferenceEquals(str1, str2))); Console.WriteLine(string.Format("ReferenceEquals(str1, str3) = {0}", ReferenceEquals(str1, str3))); </pre></div> str2 = string.Intern(str2); str3 = string.Intern(str3); Console.WriteLine(string.Format("ReferenceEquals(str1, str2) = {0}", ReferenceEquals(str1, str2))); Console.WriteLine(string.Format("ReferenceEquals(str1, str3) = {0}", ReferenceEquals(str1, str3)));</pre></div> str1 = string.Intern(str1); Console.WriteLine(string.Format(@"String.IsInterned(str1) = {0}", String.IsInterned(str1) != null));</pre></div> private static void Test(int testCount, int stringLength) { NormalCompare1(string.Empty, string.Empty); NormalCompare2(string.
read morePosts
[.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
[.NET Concept]使用BeginXXX/EndXXX與SuspendLayout/ResumeLayout時,考慮加上Try/Finally
Private Sub Application_ThreadException(ByVal sender As Object, ByVal e As EventArgs) ... End Sub</pre></div>
read morePosts
[.Net Concept]適時採用事件動態繫結來替代用If判斷作功能的啟用
Private _enableLogData As Boolean Public Property EnableLogData() As Boolean Get Return _enableLogData End Get Set(ByVal value As Boolean) _enableLogData = value End Set End Property Event Executing As EventHandler Event Executed As EventHandler Protected Sub OnExecuting(ByVal e As EventArgs) RaiseEvent Executing(Me, e) End Sub Protected Sub OnExecuted(ByVal e As EventArgs) RaiseEvent Executed(Me, e) End Sub Sub GoExecute() For i As Integer = 1 To 100000000 OnExecuting(New EventArgs) '運行動作,這邊為了看出差異,故不做動作 If EnableLogData Then '紀錄動作,這邊為了看出差異,故不做動作 End If OnExecuted(New EventArgs) Next End Sub End Class
read morePosts
[.NET Concept][Security].NET程式保護機制概述
//不影響結果 if(i == a){ Console.WriteLine("Some Thing Error!!"); } } 3.加入一些冗贅的運算 int a = 10;改為 int b = 2; int c = 5; int a = b * c; 值得注意的是,使用混淆保護的程式仍是可以使用反組譯工具看到混淆後的MSIL,且很容易被有心人反推回去的,只是增加了反推的難度而已。微軟自帶的Dotfuscator Community Edition好像已經有現成反推回去的程式在網路上流佈,像水瓶大介紹的DF Stack就是一例。 內核級加密保護若採用內核級加密來保護,使用反組譯工具去看MSIL時。會顯示不是CLR程式,無法看到反組譯過後的程式碼。有比混淆稍微安全些的感覺。類似的軟體有MaxToCode、XeonCode。 硬體保護硬體保護方面,有聖天狗、Aladdin等硬體加密鎖。多半這類產品除了本身會提供API可以讓程式呼叫做保護的動作外,也會附上基本的混淆與程式加密功能。 Conclusion在.NET保護這塊我涉略不深,只能做初步的介紹。這邊我要順帶一提,其實我們用來反組譯的.NET Reflector工具在加密上算是還做的不錯。畢竟本身就是反組譯用的工具,在這方面會有一定的程度,網路上也有許多相關研究。有興趣的可以從該工具的保護機制著手研究。像是Reflector保護方法初探等,還有很多篇,請自行打上關鍵字Reflector 保護,Google一下就有了。 LinkMSDN大內高手專欄 - To De or Not to De? DF Stack 1.0 - .NET 的反混淆器?DF StackReflector保護方法初探
read morePosts
[.NET Concept][C#][VB.NET].NET兩個表單間的資料互通
Public Class Form2 … Public MainForm As Form1 … ‘Form2透過Form1傳進的物件參考控制Form1 MainForm.Value = Me.NumericUpDown1.Value … End Class
read morePosts
[.NET Concept][C#][VB.NET]四捨六入五成雙
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, “Courier New”, courier, monospace; background-color: #ffffff; /white-space: pre;/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .
read more