C#, the natural progression

With Visual J++ in the dumpster, Microsoft introduces C# to fill the void

1 2 Page 2
Page 2 of 2
  • RAD features

    • Makes use of Java-style garbage collection
    • Makes use of Java- and Delphi-style value/reference-type system instead of pointers
    • Interfaces are declared independently of classes
    • Combines declaration and definition of class methods
    • Uses method references (similar to Delphi's procedural types) to quickly connect objects and methods
    • Makes use of Java's mechanism for simple thread synchronization
    • Makes use of Explicit override declarations
  • Other

    • Runtime component works much like a Java virtual machine
    • .Net runtime grants programmatic access to platform-native resources
    • Attributes provide support for both the COM and .Net platforms

C++ features not implemented in C#:

  • Scoping operator
  • Dereferencing accessor
  • Reference-declaration syntax
  • Templates


Other C# features

Considering all the language features just discussed, strong support for RAD appears to be one of Microsoft's most significant goals for C#. There are other important development needs, however, that C# must address. These include cross-platform deployment, access to platform-native resources, and support for the COM and .Net platforms. Let's examine the C# language features intended to support these demands.

  • Cross-platform deployment: C# solves the problem of cross-platform deployment the same way that Java does. The C# compiler generates a bytecode stream that is interpreted by the .Net runtime. The runtime component works much like a Java Virtual Machine; an application can be deployed to any device to which the .Net runtime has been ported.
  • Application access to platform-native resources- Unlike the Java virtual machine, however, the .Net runtime grants programmatic access to platform-native resources. A C# program can, for example, take advantage of the Windows API to run as a full-featured application on Windows 2000. The same program can also run on a PDA by using the Windows CE API subset. Naturally, not all of the services that the application might expect will be available on all devices. It is therefore the developer's responsibility to test the software on all target platforms, and to write special-case code, if necessary, that will allow the system to function in the absence of expected services.
  • Support for COM and .Net: To support both the COM and .Net platforms, C# includes a unique language feature called attributes. An attribute is actually a C# class that embellishes source code in order to provide metainformation. Attributes allow C# to support specific technologies such as COM and .Net without cluttering the language specification itself.

    For example, C# provides attribute classes that convert C# interfaces into COM interfaces. Others convert C# classes into COM coclasses. No IDL or class factory is necessary for performing these conversions. Some language observers have stated that all C# classes are COM objects. This is not true -- but with the proper attributes, any C# class can easily be exposed as a COM object.

    Another attribute library provided with the compiler wraps C# classes and functions as Web services. A Web service is a hosted software module that is callable over the Internet through an interaction protocol such as SOAP. SOAP wraps method calls, along with their parameters and return values, in XML data packets. Web services can be written in many languages and deployed to many hardware and software platforms. Moreover, different kinds of Web services can cooperate to make up an entire Web application. Using the proper attributes, a programmer can easily turn any C# class or function into a Web service.

Features not found in C#

Consistent with Anders Hejlsberg's history, many of the features that C# uses in support of Internet applications are culled from Delphi and Java. Yet Microsoft claims that C# descends from C and C++. Let us therefore examine some of the C++ features that are missing from C#.

  • Scoping and dereferencing operators: C# does not use the C++ scoping operator (::); instead, it relies upon the Delphi and Java equivalent, the dot operator (.). Furthermore, because it is based on the Java- and Delphi-style value/reference-type system described earlier, C# does not in most cases use the C++ dereferencing accessor (->). Instead, it again implements the dot operator. While the overloaded dot operator may confuse C++ programmers who are just learning C#, it will be quite familiar to Java and Delphi developers.
  • Reference declaration syntax: Because class, interface, and delegate types are references by default, C# lacks the reference declaration syntax of C++. Instead, the new language uses a syntax similar to Delphi's for declaring pass-by-reference parameters:

    • An unmarked parameter is input
    • The ref keyword indicates an input/output parameter (similar to Delphi's var)
    • The out keyword indicates an output parameter
    • The params keyword indicates a variable-length parameter list (similar to Delphi's variant open-array parameters)
  • Templates: Like Java and Delphi, C# does not have templates. Consequently, it has no mechanism to support the type-safe declaration of collections. Instead, every class is ultimately derived from the common base class object. A generic collection class must be a collection of objects, requiring an unsafe downcast of its members to the desired type.

Still, even without these C++ language features, C# is a powerful programming language, designed around Java- and Delphi-like features to support Internet applications. C++, because of its machine-level focus and its lack of RAD support, would not have been an appropriate basis for an Internet application-development language. Any C++ developer who needs to write applications and services for the .Net platform will be well advised to learn C# when it is released -- remembering that it differs more from C++ than its name might suggest.

In the interim, it may be best to learn Java or Delphi. Not only will these languages get you one step closer to an understanding of C#, they are also useful languages in their own right. As software professionals, we should take advantage of the best tools available.

Michael L. Perry has been a professional Windows developer for over six years and maintains expertise in COM+, Java, XML, and other technologies currently shaping the programming landscape. He formed Mallard Software Designs in 1998, where he applies the mathematical rigor of proof -- establishing the correctness of a solution before implementing it -- to software design.

Learn more about this topic

1 2 Page 2
Page 2 of 2