C#從零開始_自學C#、Visual Studio實境秀 32/ Constructors Finalizers



32/ Constructors Finalizers {

Constructors (C# Programming Guide) http://bit.ly/2uq6jUN

2:00:00 A constructor is a method whose name is the same as the name of its type.Its method signature includes only the method name and its parameter list; it does not include a return type.

2:52:00 If you don't provide a static constructor to initialize static fields, the C# compiler will supply a default static constructor that initializes static fields to their default value as listed in the Default Values Table.

{Expression-bodied members (C# programming guide) http://bit.ly/2vts8j3 expression body definition

就是以運算式為體的(class)成員表述式。} 3:16:20 圓滿

{http://bit.ly/2uqjZix Using Constructors (C# Programming Guide)

You can prevent a class from being instantiated by making the constructor private,

Private Constructors (C# Programming Guide) http://bit.ly/2u0iPHP

很多不必要創建一個執行個體的 class 應該都要加一個私用的建構子:The declaration of the empty constructor prevents the automatic generation of a default constructor.

9:00 所以斷句好重要(九陽神功 第一招)

Private constructors are used to prevent creating instances of a class

when there are no instance fields or methods, such as the Math class,

or when a method is called to obtain an instance of a class. If all the methods in the class are static, consider making the complete class static. For more information see Static Classes and Static Class Members.

29:00 再完善 google_translation-ConsoleApp 使用 IndexOf 和 Trim

39:00 override ToString() 試作

44:30 How to: Write a Copy Constructor (C# Programming Guide) http://bit.ly/2v99c9V

Copy Constructor 複製建構子其實就是一個建構子,只是它的功能是複製一個 instance(object) 給另一個 instance(object)用。關鍵就是把某一個已經建構的執行個體( instance object)的 member 及其 value 當作新建構出來的執行個體的預設值。

47:33 還有4個斜線的註解。////

1:23:00 base (C# Reference) http://bit.ly/2u0V96i

1:31:00 不一定要用 new 才能 call constructor ;是在 constructor 有 parameter 時才需要用 new; http://bit.ly/2uqjZix

1:32:00 Classes and structs can also define multiple constructors 建構子的多載 overloading

}

3:21:00 Finalizers (C# Programming Guide) http://bit.ly/2u1b1r9

3:38:00 3:41:10 Object.Finalize Method http://bit.ly/2tiGQwY

{3:50:00  Finalize Collect

Using Finalizers to Release Resources

Explicit Release of Resources

You do this by implementing a Dispose method from the IDisposable interface that performs the necessary cleanup for the object. This can considerably improve the performance of the application.

}



}


留言

熱門文章