Unformatted text preview:

CIS 24: Project 2Introduction to C#Code Documentation FacilitiesEx: standard commentIOConcurrent ProgrammingGarbage Collection:CIS 24: Project 2 Introduction to C# Authors: Steven Hamilton Adam Brown CIS 24 Mondays 6:30 – 9:10 Dr. KopecIntroduction: C# (pronounced Cee – sharp), coauthored by Anders Hejsberg (designer of the Turbo Pascal Compiler, and Delphi, another object-oriented language that allows graphical user interfaces to be constructed in much the same way as Visual Basic) and Scott Wiltamuth, is the latest and greatest object-oriented programming language from Bill Gates’ Microsoft. It is “a strongly-typed language designed to give the optimum blend of simplicity, expressiveness, and performance.”1 It draws heavily from C++ and Java, which can be seen in the syntax (or code), although it is said to keep other languages “in hindsight.”1 Runtime: One of the major features of the C# language is how closely associated it is with the .NET framework. The .NET platform has, at its center, the Common Language Runtime (CLR) “and a set of libraries which can be exploited by a wide variety of languages which are able to work together by all compiling to an intermediate language (IL).”1 Here is one of the main items that have given people the impression of C#’s similarity to Java. The CLR is a lot like the Java Virtual Machine, “a software "execution engine" that safely and compatibly executes the byte codes in Java class files on a microprocessor”2, which is what makes the Java language work. The .NET platform’s main purpose is to provide connectivity between languages. Since languages within the .NET framework all compile to the IL, they can interact with each other rather well. C# is “a little symbiotic: some features of C# are there to workwell with .NET, and some features of .NET are there to work well with C# (though .NET aims to work well with many languages)”1. Type System: The C# type system is based on two base types: Value Types, and Reference Types. Value types are like primitive types in Java and C++ (i.e.-int, boolean, char). Reference types are like Objects in C++ Java Type conversions are handled in the expected ways. Implicit conversions are automatically done when widening occurs and explicit conversions can be forced through casting. Casting and implicit conversions follow the same conventions and rules as C++ and Java. Code Documentation Facilities The only thing more important than the source code, is the documentation of the source code. It is even argued by some, that the documentation is equally, if not more, important than the source. C# provides a very clearly structured mechanism for documenting code using XML. These specially formed comments may be parsed out later to produce robust, complete documentation. Ex: standard comment // this is a standard comment Ex: XML comment /// <summary> xml comment </summary> Technically an XML solution is far superior to any other documentation facility every implemented to date. The real question is whether developers will actually use theverbose XML format for code documentation or fall back on easier, less verbose mechanisms. Classes and Objects Class declarations are syntactically and semantically equivalent to C++ and Java. Ex: class MyClass{ ... code ... } The declaration scoping modifiers are similar to C++ and Java Fields and Properties: C# has implemented properties for fields, a concept that VB developers will be familiar with, but which will seem awkward to C, C++, and Java developers. Properties allow limiting variable access. In Java, and C++, in order to protect a member variable, or field, it must be declared private or protected, and then accessor methods must be written to allow getting and setting of the value. C# allows properties to be set, which mechanically is similar to VB. For example, the following code demonstrates: Ex: private int i = 0; public int i { get{ return i; } set{ this.i = value; }} *note: anyone who is devoted to pure OO should find this feature of C# to be rediculous and unnecessary. It in fact lends itself to “break” OO methodology by giving the appearance that a member field is publically accessible, when actually it may not be based on the properties set . OO Classes may be declared abstract, and may inherit from a super class. Multiple inheritance in C# is not allowed. C# follows all standard OO conventions for overloading, over-riding, inheritance and scoping. Nested classes are supported, that is the definition of one class within another, but Anonymous nested classes are not supported. C++ has function pointers, and Java has full reflection of classes. C# has provided its own similar functionality through Delegates. Delegates provide a way for C# code to establish a relationship between a variable, and one or more concrete functions. Both C++ and Java could also precisely duplicate the functionality of C# delegates, but C# has simply made it a formalized part of the language. The measure of any true OO implementation is the presence or lack of reflection. Reflection is the ability for the application to inspect its own object environment. Java and C++ provide reflection, and so does C# through System.Reflection namespace. NamespacesNamespace declaration in C# is exactly the same as C++, and similar to Java, although all are functionally equivalent. There is a slight difference in syntax, but other than that, the meaning is the same. Ex: c++ AND c# namespace declaration namespace root.sub.mynamespace{ ... your declarations ... } Ex: java namespace declaration package root.sub.mynamespace; To use a specific namespace, you use the “using” keyword followed by the namespace you wish to reference. This is identical to C++, and functionally equivalent to the Java “import” statement. Exception Handling C# has exception handling virtually identical to Java and C++. Here is a small example to demonstrate: try { a = 10 / b; } catch ( Exception e ) { Console.WriteLine ( e ) ; } IO IO is made available through standard library objects. Anyone familiar with Java or C++ will immediately recognize how to handle standard IO. C# also supports the notions of streams, also through standard interfaces and existing library objects.Ex: Console.WriteLine("Hello World"); Concurrent Programming Threading is supported intrinsically through a


View Full Document

CUNY CISC 3160 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?