1. Trang chủ
  2. » Công Nghệ Thông Tin

a programmers guide to c# 5.0 4th edition v413hav

443 4,7K 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 443
Dung lượng 4,88 MB

Nội dung

[...]... Classes and Inheritance Sealed Classes and Methods Sealed classes are used to prevent a class from being used as a base class It is primarily useful to prevent unintended derivation: // error sealed class MyClass { MyClass() {} } class MyNewClass : MyClass { } This fails because MyNewClass can’t use MyClass as a base class because MyClass is sealed Sealed classes are useful in cases where a class isn’t designed... data types is that it is possible to write literal values for the built-in types Data types are separated into value types and reference types Value types are either stack allocated or allocated inline in a structure Reference types are heap allocated Both reference and value types are derived from the ultimate base class object In cases where a value type needs to act like an object, a wrapper that... abstract class, the TypeName() member function is marked as an abstract function, which means that all classes that derive from Engineer will be required to implement the TypeName() function An abstract class defines a contract that derived classes are expected to follow.4 Because an abstract class is missing “required” functionality, it can’t be instantiated, which for the example means that instances... true that modern IDEs have made it much easier to understand the type of a variable with minimal effort, I still find it very useful to know which variables are instance variables and which ones are local variables or parameters I am also not a fan of having to use “this.” in constructors to disambiguate I preferred the second syntax for a while but have since converted to using the third syntax, which... code needs to add support for a new engineer, the base class must be modified If a user who doesn’t have access to the base class needs to add a new type of engineer, it won’t work at all Virtual Functions To make this work cleanly, object-oriented languages allow a function to be specified as virtual Virtual means that when a call to a member function is made, the compiler should look at the real type... engineers[1].CalculateCharge(0.75F)); } } 26 Chapter 4 ■ Base Classes and Inheritance The CalculateCharge() and TypeName() functions are now declared with the virtual keyword in the base class, and that’s all that the base class has to know It needs no knowledge of the derived types, other than to know that each derived class can override CalculateCharge() and TypeName() if desired In the derived class, the functions are... example, there is a class named Point, with two integers in the class named m_x and m_y These members are public, which means that their values can be accessed by any code that uses the class In addition to the data members, there is a constructor for the class, which is a special function that is called to help construct an instance of the class The constructor takes two integer parameters It is called... what a specific obfuscator can give you before decided to use it to obfuscate your code NGEN NGEN (Native Image Generator) is a tool that performs the translation from IL to native processor code before the program is executed, rather than doing it on demand At first glance, this seems like a way to get around many of the disadvantages of the just-in-time (JIT) approach; simply pre-JIT the code, and... The garbage collector used in the NET Runtime is discussed in Chapter 39 At this point it is reasonable to just assume that it handles all the memory for you 1 2  11 Chapter 3 ■ Classes 101 C# Field Naming Conventions There are a few common choices for the naming of fields in C# classes: • A bare name: “salary” • A name preceded by an underscore: “_salary” • A name preceded by “m_”: “m_salary” • An uppercase... uppercase name preceded by “m_”: “m_Salary” In the early days of NET and C#, there was a conscious decision to move far away from the Hungarian notation common in C/C++ code, the convention that gave us names such as lpszName Most of the early code that I wrote3 used the bare name syntax, but since then I’ve been in groups that have used the other syntaxes and have written a fair amount of code in all . unmanaged code• Creating and calling code dynamically• 1 Java is another managed language; it runs using the Java Virtual Machine (JVM), and Visual Basic is of course another language that runs. variables are instance variables and which ones are local variables or parameters. I am also not a fan of having to use “this.” in constructors to disambiguate. I preferred the second syntax. System.Globalization namespace is used to help with globalization, the System.XML namespace is used to manipulate XML, and so on. Layered on top of the BCL are specialized libraries that are targeted to

Ngày đăng: 31/03/2014, 16:40

TỪ KHÓA LIÊN QUAN