Académique Documents
Professionnel Documents
Culture Documents
Learning to Program in C#
Amy Roberge & John Linehan
November 7, 2005
Applied Computing Technology Laboratory
Developed in 2000
Created by Microsoft as part of their .NET platform to
unite programming languages for web based usage
Microsoft chose the chief programmer of Delphi,
Anders Hejlsberg, to lead the development of C#
Based on C++ and Java. More of an extension of
existing languages than a new one.
The name C# is supposed to be a progression of C++
and the # contains four + symbols
.NET is proprietary. Mono is an open source project
led by Novell to make a compatible set of .NET tools
Applied Computing Technology
C# vs. Java
Similarities
Require a virtual
machine
Similar syntax
Automatic garbage
collection
Object oriented
Large class library
C# over Java
Allows structs
Switch statements can
be applied to strings
(vs. characters or
numbers)
Support for output
parameters, allowing
multiple values to be
returned
C# Advantages
Only
C# Disadvantages
Requires
to run
More
overhead
Doesnt
C# Specification
Explains:
Grammar
Structure
Generics
Types, values, variables, iterators
Type conversions and promotions
Classes, methods
Arrays, exceptions, execution, blocks, statements,
expressions, declarations, interfaces, arguments
C# Grammar
Example:
Type:
Identifier [TypeArguments]{ . Identifier [TypeArguments]} {[]}
BasicType
TypeArguments:
< TypeArgument {, TypeArgument} >
TypeArgument:
Type ? [( extends | super ) Type]
Identifier:
IDENTIFIER
BasicType:
byte | short | char | int | long | float | double | boolean
Reserved Words
abstract
as
base
bool
break
byte
case
catch
char
checked
class
const
continue
decimal
default
delegate
do
double
else
enum
event
explicit
extern
false
finally
fixed
float
for
foreach
goto
if
implicit
in
int
interface
internal
is
lock
long
namespace
new
null
object
operator
out
override
params
private
protected
public
readonly
ref
return
sbyte
sealed
short
sizeof
stackalloc
static
string
struct
switch
this
throw
true
try
typeof
uint
ulong
unchecked
unsafe
ushort
using
virtual
void
volatile
while
SDK 1.1:
http://www.microsoft.com/downloads/details.aspx?familyid=9b3a2ca6-3647-4070
-9f41-a333c6b9181d&displaylang=en
Double-click
Step 2: SharpDevelop
Opensource
IDE
Download & install SharpDevelop from:
http://www.icsha`rpcode.net/OpenSource/SD/Download/
Run
10
11
Hello World
using System;
namespace Hello_World
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Applied Computing Technology
12
Build
Select Build Combine
View the console at the bottom for
progress
After the file is compiled, select Debug
and then click Run.
Watch the command prompt window
open and display the output
Applied Computing Technology
13
Visit
http://actlab.csc.villanova.edu/quickstart
Visit C# Station
http://www.csharp-station.com/
http://msdn.microsoft.com/vcsharp/
Find
Helpful C# tools
http://msdn.microsoft.com/vcsharp/programming/tools/
Wikipedia
http://en.wikipedia.org/wiki/C_Sharp
Applied Computing Technology
14