Thinking in C# phần 4
➤ Gửi thông báo lỗi ⚠️ Báo cáo tài liệu vi phạmNội dung chi tiết: Thinking in C# phần 4
Thinking in C# phần 4
But be careful with your assumptions, In general, it's difficult to anticipate how a class can be reused, especially a general-purpose class. Unless y Thinking in C# phần 4 you declare a method as virtual, you prevent the possibility of reusing your class through inheritance in some other programmer’s project simply because you couldn’t imagine it being used that wayInitialization andclass loadingIn more traditional languages, programs are loaded all at once as part of Thinking in C# phần 4 the startup process. Tills is followed by initialization, and then the program begins. The process of initialization in these languages must be carefThinking in C# phần 4
ully controlled so that the order of initialization of statics doesn’t cause trouble. C++, for example, has problems if one static expects another staBut be careful with your assumptions, In general, it's difficult to anticipate how a class can be reused, especially a general-purpose class. Unless y Thinking in C# phần 4 ything in Ci? is an object, many activities become easier, and this is one of them. As you will learn more fully in the next chapter, the compiled code for a set of related classes exists in their own separate file, called an assembly. That file isn’t loaded until the code is needed. In general, you Thinking in C# phần 4 can say that -Class code IS loaded at the point of first use." Tins IS often not until the first object of that class is constructed, but loading alsThinking in C# phần 4
o occurs when a static field or static method is accessedThe point of first use is also where the static initialization takes place. All the static obBut be careful with your assumptions, In general, it's difficult to anticipate how a class can be reused, especially a general-purpose class. Unless y Thinking in C# phần 4 t of loading. The statics, of course, are initialized only once.Initialization with inheritanceIt’s helpful to look at the whole initialization process, including inheritance, to get a full picture of what happens. Consider the following code://:c07:Beetle.cs// The full process of initialization.usi Thinking in C# phần 4 ng System;class Insect {in- i 9;internal int j;Chapter 7: Reusing Classes 255internal Insect 0 {PrtC’i - + Ỉ + ", J ” + J);j - 39;1static int Xi PrThinking in C# phần 4
t("static Insect.xl initialized");internal static mt Prt(string s) {Console.WriteLine(s);return 47;1Jclass Beetle : Insect (int k - Prt ("Beetle.k iniBut be careful with your assumptions, In general, it's difficult to anticipate how a class can be reused, especially a general-purpose class. Unless y Thinking in C# phần 4 tructor");Beetle b - new Beetle ();But be careful with your assumptions, In general, it's difficult to anticipate how a class can be reused, especially a general-purpose class. Unless yGọi ngay
Chat zalo
Facebook