Archive for January, 2008

18 CHAPTER 1 THE PHILOSOPHY OF .NET (Virtual web hosting)

Sunday, January 13th, 2008

18 CHAPTER 1 THE PHILOSOPHY OF .NET CTS Type Members Now that you have previewed each of the types formalized by the CTS, realize that most types take any number of members. Formally speaking, a type member is constrained by the set {constructor, finalizer, static constructor, nested type, operator, method, property, indexer, field, read only field, constant, event}. The CTS defines various adornments that may be associated with a given member. For example, each member has a given visibility trait (e.g., public, private, protected, and so forth). Some members may be declared as abstract to enforce a polymorphic behavior on derived types as well as virtual to define a canned (but overridable) implementation. Also, most members may be configured as static (bound at the class level) or instance (bound at the object level). The construction of type members is examined over the course of the next several chapters. Note As described in Chapter 10, .NET 2.0 supports the construction of generic types and generic members. Intrinsic CTS Data Types The final aspect of the CTS to be aware of for the time being is that it establishes a well-defined set of core data types. Although a given language typically has a unique keyword used to declare an intrinsic CTS data type, all language keywords ultimately resolve to the same type defined in an assembly named mscorlib.dll. Consider Table 1-3, which documents how key CTS data types are expressed in various .NET languages. Table 1-3. The Intrinsic CTS Data Types CTS Data Type VB .NET Keyword C# Keyword Managed Extensions for C++ Keyword System.Byte Byte byte unsigned char System.SByte SByte sbyte signed char System.Int16 Short short short System.Int32 Integer int int or long System.Int64 Long long __int64 System.UInt16 UShort ushort unsigned short System.UInt32 UInteger uint unsigned int or unsigned long System.UInt64 ULong ulong unsigned __int64 System.Single Single float Float System.Double Double double Double System.Object Object object Object^ System.Char Char char wchar_t System.String String string String^ System.Decimal Decimal decimal Decimal System.Boolean Boolean bool Bool
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Hosting your own web site - CHAPTER 1 THE PHILOSOPHY OF .NET 17

Saturday, January 12th, 2008

CHAPTER 1 THE PHILOSOPHY OF .NET 17 CTS Interface Types Interfaces are nothing more than a named collection of abstract member definitions, which may be supported (i.e., implemented) by a given class or structure. Unlike COM, .NET interfaces do not derive a common base interface such as IUnknown. In C#, interface types are defined using the interface keyword, for example: // A C# interface type. public interface IDraw { void Draw(); } On their own, interfaces are of little use. However, when a class or structure implements a given interface in its unique way, you are able to request access to the supplied functionality using an interface reference in a polymorphic manner. Interface-based programming will be fully explored in Chapter 7. CTS Enumeration Types Enumerations are a handy programming construct that allows you to group name/value pairs. For example, assume you are creating a video-game application that allows the player to select one of three character categories (Wizard, Fighter, or Thief). Rather than keeping track of raw numerical values to represent each possibility, you could build a custom enumeration using the enum keyword: // A C# enumeration type. public enum CharacterType { Wizard = 100, Fighter = 200, Thief = 300 } By default, the storage used to hold each item is a 32-bit integer; however, it is possible to alter this storage slot if need be (e.g., when programming for a low-memory device such as a Pocket PC). Also, the CTS demands that enumerated types derive from a common base class, System.Enum. As you will see in Chapter 3, this base class defines a number of interesting members that allow you to extract, manipulate, and transform the underlying name/value pairs programmatically. CTS Delegate Types Delegates are the .NET equivalent of a type-safe C-style function pointer. The key difference is that a .NET delegate is a class that derives from System.MulticastDelegate, rather than a simple pointer to a raw memory address. In C#, delegates are declared using the delegate keyword: // This C# delegate type can ‘point to’ any method // returning an integer and taking two integers as input. public delegate int BinaryOp(int x, int y); Delegates are useful when you wish to provide a way for one entity to forward a call to another entity, and provide the foundation for the .NET event architecture. As you will see in Chapters 8 and 14, delegates have intrinsic support for multicasting (i.e., forwarding a request to multiple recipients) and asynchronous method invocations.
We recommend high quality webhost to host and run your jsp application: christian web host services.

16 CHAPTER 1 THE PHILOSOPHY OF (Cedant web hosting) .NET

Friday, January 11th, 2008

16 CHAPTER 1 THE PHILOSOPHY OF .NET CTS Class Types Every .NET-aware language supports, at the very least, the notion of a class type, which is the cornerstone of object-oriented programming (OOP). A class may be composed of any number of members (such as properties, methods, and events) and data points (fields). In C#, classes are declared using the class keyword: // A C# class type. public class Calc { public int Add(int x, int y) { return x + y; } } Chapter 4 examines the process of building CTS class types with C#; however, Table 1-2 documents a number of characteristics pertaining to class types. Table 1-2. CTS Class Characteristics Class Characteristic Meaning in Life Is the class sealed or not? Sealed classes cannot function as a base class to other classes. Does the class implement any An interface is a collection of abstract members that interfaces? provide a contract between the object and object user. The CTS allows a class to implement any number of interfaces. Is the class abstract or concrete? Abstract classes cannot be directly created, but are intended to define common behaviors for derived types. Concrete classes can be created directly. What is the visibility of this class? Each class must be configured with a visibility attribute. Basically, this trait defines if the class may be used by external assemblies, or only from within the defining assembly (e.g., a private helper class). CTS Structure Types The concept of a structure is also formalized under the CTS. If you have a C background, you should be pleased to know that these user-defined types (UDTs) have survived in the world of .NET (although they behave a bit differently under the hood). Simply put, a structure can be thought of as a lightweight class type having value-based semantics. For more details on the subtleties of structures, see Chapter 3. Typically, structures are best suited for modeling geometric and mathematical data, and are created in C# using the struct keyword: // A C# structure type. struct Point { // Structures can contain fields. public int xPos, yPos; // Structures can contain parameterized constructors. public Point(int x, int y) { xPos = x; yPos = y;} // Structures may define methods. public void Display() { Console.WriteLine(”({0}, {1}”, xPos, yPos); } }
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

CHAPTER 1 THE (Web server application) PHILOSOPHY OF .NET 15

Thursday, January 10th, 2008

CHAPTER 1 THE PHILOSOPHY OF .NET 15 Metadata is used by numerous aspects of the .NET runtime environment, as well as by various development tools. For example, the IntelliSense feature provided by Visual Studio 2005 is made possible by reading an assembly s metadata at design time. Metadata is also used by various object browsing utilities, debugging tools, and the C# compiler itself. To be sure, metadata is the backbone of numerous .NET technologies including remoting, reflection, late binding, XML web services, and object serialization. The Role of the Assembly Manifest Last but not least, remember that a .NET assembly also contains metadata that describes the assembly itself (technically termed a manifest). Among other details, the manifest documents all external assemblies required by the current assembly to function correctly, the assembly s version number, copyright information, and so forth. Like type metadata, it is always the job of the compiler to generate the assembly s manifest. Here are some relevant details of the CSharpCalculator.exe manifest: .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) .ver 2:0:0:0 } .assembly CSharpCalculator { .hash algorithm 0×00008004 .ver 0:0:0:0 } .module CSharpCalculator.exe .imagebase 0×00400000 .subsystem 0×00000003 .file alignment 512 .corflags 0×00000001 In a nutshell, this manifest documents the list of external assemblies required by CSharpCalculator. exe (via the .assembly extern directive) as well as various characteristics of the assembly itself (version number, module name, and so on). Understanding the Common Type System A given assembly may contain any number of distinct types. In the world of .NET, type is simply a generic term used to refer to a member from the set {class, structure, interface, enumeration, delegate}. When you build solutions using a .NET-aware language, you will most likely interact with each of these types. For example, your assembly may define a single class that implements some number of interfaces. Perhaps one of the interface methods takes an enumeration type as an input parameter and returns a structure to the caller. Recall that the Common Type System (CTS) is a formal specification that documents how types must be defined in order to be hosted by the CLR. Typically, the only individuals who are deeply concerned with the inner workings of the CTS are those building tools and/or compilers that target the .NET platform. It is important, however, for all .NET programmers to learn about how to work with the five types defined by the CTS in their language of choice. Here is a brief overview.
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

14 CHAPTER 1 THE PHILOSOPHY OF .NET (Com web hosting)

Wednesday, January 9th, 2008

14 CHAPTER 1 THE PHILOSOPHY OF .NET Compiling CIL to Platform-Specific Instructions Due to the fact that assemblies contain CIL instructions, rather than platform-specific instructions, CIL code must be compiled on the fly before use. The entity that compiles CIL code into meaningful CPU instructions is termed a just-in-time (JIT) compiler, which sometimes goes by the friendly name of Jitter. The .NET runtime environment leverages a JIT compiler for each CPU targeting the runtime, each optimized for the underlying platform. For example, if you are building a .NET application that is to be deployed to a handheld device (such as a Pocket PC), the corresponding Jitter is well equipped to run within a lowmemory environment. On the other hand, if you are deploying your assembly to a back-end server (where memory is seldom an issue), the Jitter will be optimized to function in a highmemory environment. In this way, developers can write a single body of code that can be efficiently JIT-compiled and executed on machines with different architectures. Furthermore, as a given Jitter compiles CIL instructions into corresponding machine code, it will cache the results in memory in a manner suited to the target operating system. In this way, if a call is made to a method named PrintDocument(), the CIL instructions are compiled into platformspecific instructions on the first invocation and retained in memory for later use. Therefore, the next time PrintDocument() is called, there is no need to recompile the CIL. The Role of .NET Type Metadata In addition to CIL instructions, a .NET assembly contains full, complete, and accurate metadata, which describes each and every type (class, structure, enumeration, and so forth) defined in the binary, as well as the members of each type (properties, methods, events, and so on). Thankfully, it is always the job of the compiler (not the programmer) to emit the latest and greatest type metadata. Because .NET metadata is so wickedly meticulous, assemblies are completely self-describing entities so much so, in fact, that .NET binaries have no need to be registered into the system registry. To illustrate the format of .NET type metadata, let s take a look at the metadata that has been generated for the Add() method of the C# Calc class you examined previously (the metadata generated for the VB .NET version of the Add() method is similar): TypeDef #2 (02000003) ——————————————————- TypDefName: CalculatorExample.Calc (02000003) Flags : [Public] [AutoLayout] [Class] [AnsiClass] [BeforeFieldInit] (00100001) Extends : 01000001 [TypeRef] System.Object Method #1 (06000003) ——————————————————- MethodName: Add (06000003) Flags : [Public] [HideBySig] [ReuseSlot] (00000086) RVA : 0×00002090 ImplFlags : [IL] [Managed] (00000000) CallCnvntn: [DEFAULT] hasThis ReturnType: I4 2 Arguments Argument #1: I4 Argument #2: I4 2 Parameters (1) ParamToken : (08000001) Name : x flags: [none] (00000000) (2) ParamToken : (08000002) Name : y flags: [none] (00000000)
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

CHAPTER 1 THE PHILOSOPHY OF .NET (Ecommerce web host) 13

Tuesday, January 8th, 2008

CHAPTER 1 THE PHILOSOPHY OF .NET 13 ‘ Calc.vb Imports System Namespace CalculatorExample ‘ A VB .NET ‘Module’ is a class that only contains ‘ static members. Module CalcApp Sub Main() Dim ans As Integer Dim c As New Calc ans = c.Add(10, 84) Console.WriteLine(”10 + 84 is {0}.”, ans) Console.ReadLine() End Sub End Module Class Calc Public Function Add(ByVal x As Integer, ByVal y As Integer) As Integer Return x + y End Function End Class End Namespace If you examine the CIL for the Add() method, you find similar instructions (slightly tweaked by the VB .NET compiler): .method public instance int32 Add(int32 x, int32 y) cil managed { // Code size 9 (0×9) .maxstack 2 .locals init ([0] int32 Add) IL_0000: nop IL_0001: ldarg.1 IL_0002: ldarg.2 IL_0003: add.ovf IL_0004: stloc.0 IL_0005: br.s IL_0007 IL_0007: ldloc.0 IL_0008: ret } // end of method Calc::Add Benefits of CIL At this point, you might be wondering exactly what is gained by compiling source code into CIL rather than directly to a specific instruction set. One benefit is language integration. As you have already seen, each .NET-aware compiler produces nearly identical CIL instructions. Therefore, all languages are able to interact within a well-defined binary arena. Furthermore, given that CIL is platform-agnostic, the .NET Framework itself is platform-agnostic, providing the same benefits Java developers have grown accustomed to (i.e., a single code base running on numerous operating systems). In fact, there is an international standard for the C# language, and a large subset of the .NET platform and implementations already exist for many non-Windows operating systems (more details at the conclusion of this chapter). In contrast to Java, however, .NET allows you to build applications using your language of choice.
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Web site template - 12 CHAPTER 1 THE PHILOSOPHY OF .NET

Monday, January 7th, 2008

12 CHAPTER 1 THE PHILOSOPHY OF .NET // Calc.cs using System; namespace CalculatorExample { // This class contains the app’s entry point. public class CalcApp { static void Main() { Calc c = new Calc(); int ans = c.Add(10, 84); Console.WriteLine(”10 + 84 is {0}.”, ans); // Wait for user to press the Enter key before shutting down. Console.ReadLine(); } } // The C# calculator. public class Calc { public int Add(int x, int y) { return x + y; } } } Once the C# compiler (csc.exe) compiles this source code file, you end up with a single-file *.exe assembly that contains a manifest, CIL instructions, and metadata describing each aspect of the Calc and CalcApp classes. For example, if you were to open this assembly using ildasm.exe (examined a little later in this chapter), you would find that the Add() method is represented using CIL such as the following: .method public hidebysig instance int32 Add(int32 x, int32 y) cil managed { // Code size 8 (0×8) .maxstack 2 .locals init ([0] int32 CS$1$0000) IL_0000: ldarg.1 IL_0001: ldarg.2 IL_0002: add IL_0003: stloc.0 IL_0004: br.s IL_0006 IL_0006: ldloc.0 IL_0007: ret } // end of method Calc::Add Don t worry if you are unable to make heads or tails of the resulting CIL for this method Chapter 15 will describe the basics of the CIL programming language. The point to concentrate on is that the C# compiler emits CIL, not platform-specific instructions. Now, recall that this is true of all .NET-aware compilers. To illustrate, assume you created this same application using Visual Basic .NET (VB .NET), rather than C#:
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

CHAPTER 1 THE PHILOSOPHY OF .NET 11 (Web site development)

Sunday, January 6th, 2008

CHAPTER 1 THE PHILOSOPHY OF .NET 11 implemented by SportsCar (if any), as well as a full description of each member supported by the SportsCar type. .NET metadata is a dramatic improvement to COM type metadata. As you may already know, COM binaries are typically described using an associated type library (which is little more than a binary version of Interface Definition Language [IDL] code). The problems with COM type information are that it is not guaranteed to be present and the fact that IDL code has no way to document the externally referenced servers that are required for the correct operation of the current COM server. In contrast, .NET metadata is always present and is automatically generated by a given .NET-aware compiler. Finally, in addition to CIL and type metadata, assemblies themselves are also described using metadata, which is officially termed a manifest. The manifest contains information about the current version of the assembly, culture information (used for localizing string and image resources), and a list of all externally referenced assemblies that are required for proper execution. You ll examine various tools that can be used to examine an assembly s types, metadata, and manifest information over the course of the next few chapters. Single-File and Multifile Assemblies In a great number of cases, there is a simple one-to-one correspondence between a .NET assembly and the binary file (*.dll or *.exe). Thus, if you are building a .NET *.dll, it is safe to consider that the binary and the assembly are one and the same. Likewise, if you are building an executable desktop application, the *.exe can simply be referred to as the assembly itself. As you ll see in Chapter 11, however, this is not completely accurate. Technically speaking, if an assembly is composed of a single *.dll or *.exe module, you have a single-file assembly. Single-file assemblies contain all the necessary CIL, metadata, and associated manifest in an autonomous, single, well-defined package. Multifile assemblies, on the other hand, are composed of numerous .NET binaries, each of which is termed a module. When building a multifile assembly, one of these modules (termed the primary module) must contain the assembly manifest (and possibly CIL instructions and metadata for various types). The other related modules contain a module level manifest, CIL, and type metadata. As you might suspect, the primary module documents the set of required secondary modules within the assembly manifest. So, why would you choose to create a multifile assembly? When you partition an assembly into discrete modules, you end up with a more flexible deployment option. For example, if a user is referencing a remote assembly that needs to be downloaded onto his or her machine, the runtime will only download the required modules. Therefore, you are free to construct your assembly in such a way that less frequently required types (such as a type named HardDriveReformatter) are kept in a separate stand-alone module. In contrast, if all your types were placed in a single-file assembly, the end user may end up downloading a large chunk of data that is not really needed (which is obviously a waste of time). Thus, as you can see, an assembly is really a logical grouping of one or more related modules that are intended to be initially deployed and versioned as a single unit. The Role of the Common Intermediate Language Now that you have a better feel for .NET assemblies, let s examine the role of the common intermediate language (CIL) in a bit more detail. CIL is a language that sits above any particular platform-specific instruction set. Regardless of which .NET-aware language you choose, the associated compiler emits CIL instructions. For example, the following C# code models a trivial calculator. Don t concern yourself with the exact syntax for now, but do notice the format of the Add() method in the Calc class:
Check Tomcat Web Hosting services for best quality webspace to host your web application.

10 CHAPTER 1 THE PHILOSOPHY OF .NET (Apache web server for windows)

Saturday, January 5th, 2008

10 CHAPTER 1 THE PHILOSOPHY OF .NET An Overview of .NET Assemblies Regardless of which .NET language you choose to program with, understand that despite the fact that .NET binaries take the same file extension as COM servers and unmanaged Win32 binaries (*.dll or *.exe), they have absolutely no internal similarities. For example, *.dll .NET binaries do not export methods to facilitate communications with the COM runtime (given that .NET is not COM). Furthermore, .NET binaries are not described using COM type libraries and are not registered into the system registry. Perhaps most important, .NET binaries do not contain platform-specific instructions, but rather platform-agnostic intermediate language (IL) and type metadata. Figure 1-2 shows the big picture of the story thus far. Figure 1-2. All .NET-aware compilers emit IL instructions and metadata. Note There is one point to be made regarding the abbreviation IL. During the development of .NET, the official term for IL was Microsoft intermediate language (MSIL). However with the final release of .NET, the term was changed to common intermediate language (CIL). Thus, as you read the .NET literature, understand that IL, MSIL, and CIL are all describing the same exact entity. In keeping with the current terminology, I will use the abbreviation CIL throughout this text. When a *.dll or *.exe has been created using a .NET-aware compiler, the resulting module is bundled into an assembly. You will examine numerous details of .NET assemblies in Chapter 11. However, to facilitate the discussion of the .NET runtime environment, you do need to understand some basic properties of this new file format. As mentioned, an assembly contains CIL code, which is conceptually similar to Java bytecode in that it is not compiled to platform-specific instructions until absolutely necessary. Typically, absolutely necessary is the point at which a block of CIL instructions (such as a method implementation) is referenced for use by the .NET runtime. In addition to CIL instructions, assemblies also contain metadata that describes in vivid detail the characteristics of every type living within the binary. For example, if you have a class named SportsCar, the type metadata describes details such as SportsCar s base class, which interfaces are
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Frontpage web hosting - CHAPTER 1 THE PHILOSOPHY OF .NET 9

Friday, January 4th, 2008

CHAPTER 1 THE PHILOSOPHY OF .NET 9 Table 1-1. A Sampling of .NET-Aware Programming Languages .NET Language Web Link Meaning in Life http://www.oberon.ethz.ch/oberon.net Homepage for Active Oberon .NET. http://www.usafa.af.mil/df/dfcs/bios/ Homepage for A# (a port of Ada to the .NET platform). mcc_html/a_sharp.cfm http://www.netcobol.com For those interested in COBOL .NET. http://www.eiffel.com For those interested in Eiffel .NET. http://www.dataman.ro/dforth For those interested in Forth .NET. http://www.silverfrost.com/11/ftn95/ For those interested in Fortran .NET. ftn95_fortran_95_for_windows.asp http://www.vmx-net.com Yes, even Smalltalk .NET is available. Please be aware that Table 1-1 is not exhaustive. Numerous websites maintain a list of .NET-aware compilers, one of which would be http://www.dotnetpowered.com/languages.aspx (again, the exact URL is subject to change). I encourage you to visit this page, as you are sure to find many .NET languages worth investigating (LISP .NET, anyone?). Life in aMultilanguage World As developers first come to understand the language-agnostic nature of .NET, numerous questions arise. The most prevalent of these questions would have to be, If all .NET languages compile down to managed code, why do we need more than one compiler? There are a number of ways to answer this question. First, we programmers are a very particular lot when it comes to our choice of programming language (myself included). Some of us prefer languages full of semicolons and curly brackets, with as few language keywords as possible. Others enjoy a language that offers more human-readable syntactic tokens (such as Visual Basic .NET). Still others may want to leverage their mainframe skills while moving to the .NET platform (via COBOL .NET). Now, be honest. If Microsoft were to build a single official .NET language that was derived from the BASIC family of languages, can you really say all programmers would be happy with this choice? Or, if the only official .NET language was based on Fortran syntax, imagine all the folks out there who would ignore .NET altogether. Because the .NET runtime couldn’t care less which language was used to build a block of managed code, .NET programmers can stay true to their syntactic preferences, and share the compiled assemblies among teammates, departments, and external organizations (regardless of which .NET language others choose to use). Another excellent byproduct of integrating various .NET languages into a single unified software solution is the simple fact that all programming languages have their own sets of strengths and weaknesses. For example, some programming languages offer excellent intrinsic support for advanced mathematical processing. Others offer superior support for financial calculations, logical calculations, interaction with mainframe computers, and so forth. When you take the strengths of a particular programming language and then incorporate the benefits provided by the .NET platform, everybody wins. Of course, in reality the chances are quite good that you will spend much of your time building software using your .NET language of choice. However, once you learn the syntax of one .NET language, it is very easy to master another. This is also quite beneficial, especially to the consultants of the world. If your language of choice happens to be C#, but you are placed at a client site that has committed to Visual Basic .NET, you should be able to parse the existing code body almost instantly (honest!) while still continuing to leverage the .NET Framework. Enough said.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.