【正文】
function. ? Params parameters define a variable number of arguments in a list. C and the CLR work together to provide automatic memory management. You don39。s look at a realworld example that would benefit from interfaces to illustrate its extremely positive role in C. Many applications available today support addins. Assume that you have created a code editor for writing applications. This code editor, when executed, has the capability to load addins. To do this, the addin must follow a few rules. The DLL addin must export a function called CEEntry, and the name of the DLL must begin with CEd. When we run our code editor, it scans its working directory for all DLLs that begin with CEd. When it finds one, it is loaded。d like it to run on both your desktop and a handheld device. It39。s use of MSIL is that the instruction set can be easily read by a verification process. Part of the job of the JIT piler is to verify your code to ensure that it is as clean as possible. The verification process ensures that your code is accessing memory properly and that it is using the correct variable types when calling methods that expect a specific type. These checks ensure that your code doesn39。reworking with. Think of metadata as a table of contents for your piled code. The C piler places metadata in the piled code along with the generated MSIL. This metadata accurately describes all the classes you wrote and how they are structured. All of the classes39。t be building an application. Instead, you39。t need to specify whether you want to build a private or a global assembly. The difference is apparent when you deploy your assembly. With a private assembly, you make your code available to a single application. Your assembly is packaged as a DLL, and is installed into the same directory as the application using it. With a deployment of a private assembly, the only application that can use your code is the executable that lives in the same directory as your assembly. If you want to share your code among many applications, you might want to consider deploying your code as a global assembly. Global assemblies can be used by any .NET application on the system, regardless of the directory in which it is installed. Microsoft ships assemblies as a part of the .NET Framework, and each of the Microsoft assemblies is installed as a global assembly. The .NET Framework contains a list of global assemblies in a facility called the global assembly cache, and the .NET Microsoft Framework SDK includes utilities to both install and remove assemblies from the global assembly cache. In one sense, C can be seen as being the same thing to programming languages as .NET is to the Windows environment. Just as Microsoft has been adding more and more features to Windows and the Windows API over the past decade, Visual Bas ic and C++ have undergone expansion. Although Visual Basic and C++ have ended up as hugely powerful languages as a result of this, both languages also suffer from problems due to the legacies of how they have evolved. In the case of Visual Basic 6 and earlier, the main strength o。 and those classes share the same level of version control, security information, and activation requirements. Think of an assembly as a logical DLL. If you39。ve ever worked with COM (Component Object Model), you may be familiar with type libraries. Type libraries aimed to provide similar table of contents functionality for COM objects. However, type libraries suffered from some limitations, not the least of which was the fact that not all of the data relevant to the object was put into the type library. Metadata does not have this shorting. All of the information needed to describe a class in code is placed into the metadata. You can think of metadata as having all of the benefits of COM type libraries without the limitations . Assemblies Sometimes, you will use C to build an enduser application. These applications are packaged as executable files with an extension of .EXE. Windows has always worked with .EXE files as application programs, and C fully supports building .EXE files. However, there may be times when you don39。s application, you39。d need two C pilers: one that targeted your desktop CPU and another that targeted yourhandheld CPU. You39。t read MSIL? The answer is that the MSIL code is turned into CPUspecific code when the code is run for the first time. This process is called justintime pilation, or JIT. The job of a JIT piler is to translate your generic MSIL code into machine code that can be executed by your CPU. You may be wondering about what seems like an extra step in the process. Why generate MSIL when a piler could generate CPUspecific code directly? After all, pilers have always done this in the past. There are a couple of reasons for this. First, MSIL enables your piled code to be easily moved to different hardware. Suppose you39。s visibility to other objects. C supports public, protected, internal, protected internal, and private accessibility scopes. Variables Variables can be defined as constants. Constants have values that cannot change during the execution of your code. The value of pi, for instance, is a good example of a constant, because its value won39。t lose any information (for example, you can convert an int to a long without losing any data because a long is larger than an int). Explicit conversions may cause you to lose data (for example, converting a long into an int may result in a loss of data because a long can hold larger values than an int). You must write a cast operator into your code to make an explicit conversion happen. CrossReference Refer to Chapter 3, Working with V about implicit and explic it conversions. You can work with both onedimensional and multidimensional arrays in C. Multidimensional arrays can be rectangula