C#: Project Cool

Download Report

Transcript C#: Project Cool

C#: Project Cool
Arthur Ketchel II
Keith Francisco
Chris McInnis
Language Paradigm
• Simple, Modern, General Purpose
• Structured, Imperative, Objected
Oriented
• Designed for Software Component
Development
• Not designed to compete with C on
performance or size.
− JIT compiled
Historical Context
• C# was developed by Microsoft.
• Lead Architect: Anders Hejlsberg
− Worked on other languages, such as: Delphi
• Codename of C# was Project Cool
− Microsoft denies this but there is evidence to
prove otherwise in code snippets and file
paths.
• The language received its name from music, as a
sharp (#) is a semi-tone above the base note.
C#’s Origin
• Before creating C#, Microsoft implemented a modified
Java environment, called J++.
• Microsoft was said to have added features in a manner
that violated platform neutrality, violating a license
agreement that Microsoft signed with Sun Microsystems
in return for using the Java brand.
• Sun Microsystems sued and won, preventing Microsoft
from using the Java brand and thus further production
of J++. With the release of the .NET framework (and
C#), the project was revived in the form of J#.
• During the development, C# was driven by CLR or
Common Language Runtime.
• At compile-time, a .NET compiler converts such code
into CIL code. At runtime, the CLR's just-in-time
compiler converts the CIL code into code native to the
operating system
C# and Java
• Both languages are Objected Oriented, Garbage
Collected and run-time compiled (JIT).
• In Java, wrapper classes must be used for primitive
types in order to translate between their primitive data
and object forms.
− Java: Integer.toString(42);
− C#: 42.toString();
• Unlike Java, C# allows conditional compilation using
preprocessor directives.
• C# only supports unchecked exceptions, which do not
require the programmer to declare and catch all
exceptions thrown by a method.
The C Language Family
•
Comparison of C# to C and C++
− C# has no global variables or functions. All methods and
members must be declared within classes.
− In C#, local variables cannot shadow variables of the enclosing
block, unlike C and C++.
− C# supports a strict boolean type, bool, and does not allow
conversion between an integer meaning bool (0, false – 1,
true)
− In C#, multiple inheritance is not supported, although a class
can implement any number of interfaces.
− Accessors called properties can be used to modify an object
with syntax that resembles C++ member field access (get and
set).
− C# has a unified type system. This means that all types,
including primitives such as integers, are subclasses of the
System.Object class. For example, every type inherits a
ToString() method. (42.ToString() calls the ToString() method
of an integer)
C# Language Concepts
• Object Oriented
− Everything from data types to classes
inherit from a base Object class
− No global variables or methods, everything
is encased within classes.
C# Language Concepts
• Memory Management
− Memory cannot be explicitly freed.
• Memory is managed by the garbage
collector.
− Garbage collector protects against
memory leaks.
− Pointers can only be used within unsafe
code blocks.
C# Interesting Concepts
• You may use foreach on lists as well as
for loops.
• Properties can expose member variables
much like get and set methods.
• partial classes help break down large
class files.
Future Concepts (C# v3.0)
• Language Integrated Query will allow for
queries on SQL, XML, collections, and
more (from, where, select)
• Automatic properties will decrease code
length.
Code Sample (factorial – recursion)
Code Sample (factorial – foreach)
Code Sample (factorial – for)