Microsoft`s .NET

Download Report

Transcript Microsoft`s .NET

Microsoft's .NET
C# and
The Common Language
Runtime
Bill Campbell, UMB
Correspondence
Java (J2EE)
.Net
Family of Standards
Family of Products
Cross platform
Windows
Java
C# (VB, C++, Jscript)
& others
JSP
ASP+
Bill Campbell, UMB
Correspondence (cont)
Java (J2EE)
.Net
JDBC
.ADO
EJB
DCOM+
IIOP, SOAP (xml)
Remoting, SOAP
Several Vendors
One vendor
Bill Campbell, UMB
C# a language for programmers



From C and C++
Managed Data (garbage collection)
Larger than Java
• (80 vs 50 keywords)
• Preprocessing directives, #ifdef etc.
• Operator overloading
• Syntactic sugar (convenience)
Bill Campbell, UMB
Everybody's an Object
Type
(stack allocated)
(heap allocated)
Value Type
Scalar
Ref Type
Class
Enumeration
Structure
Delegate
Bill Campbell, UMB
Interface
Choice in Scalars
sbyte
byte
short
ushort
int
uint
long
ulong
float
double
decimal
Bill Campbell, UMB
char
bool
Scalars are structs
int is really syntax for Int32
struct Int32
{...
}
so, e.g.
56.ToString()
Bill Campbell, UMB
keywords
abstract
byte
class
delegate
event
fixed
if
internal
new
override
readonly
short
struct
try
void
as
case
const
do
explicit
float
implicit
is
null
params
ref
sizeof
switch
typeof
volatile
base
catch
continue
double
extern
for
in
lock
object
private
return
stackalloc
this
uint
while
Bill Campbell, UMB
bool
char
decimal
else
false
foreach
int
long
operator
protected
sbyte
static
throw
ulong
break
checked
default
enum
final
goto
interface
namespace
out
public
sealed
string
true
unchecked
foreach
foreach (int elem in intArray)
{
…
}
foreach (BankAccount acct in accounts)
{
…
}
Bill Campbell, UMB
Properties mimic field syntax
Temperature t = New Temperature(...);
...
double c = t.DegreesCelsius;
...
t.DegreesCelsius = 0.0;
double f = t.DegreesFarenheit; // 32.0
Bill Campbell, UMB
Behave like getters and setters
public double DegreesCelsius
{
get
{
return degreesCelsius;
}
set
{
degreesCelsius = value;
}
}
Bill Campbell, UMB
DegreesFahrenheit Property
public double DegreesFahrenheit
{
get
{
return 9.0/5.0*DegreesCelsius + 32.0;
}
set
{
DegreesCelsius = 5.0/9.0*(value-32.0);
}
}
Bill Campbell, UMB
Indexers
public class BitSet
{
ulong word;
public bool this[int position]
{
get
{
if (position < 0 || position > 63)
throw new IndexOutOfRangeException();
else
return word & (1 << position) != 0;
}
...
}
Bill Campbell, UMB
Properties and Indexers
Ubiquitous
button.Size
"cat".length => 3
"cat"[1] => 'a'
hashtable["key"] = "value";
...
hashtable["key"] => "value"
Bill Campbell, UMB
Boxing and Unboxing
Like Java, Collections of (Reference) Objects
hashtable["one"] = (object) 1;
// 1 boxed
int one = (int) hashtable["one"]; // unboxed
Bill Campbell, UMB
Delegates and Events
Type safe callbacks
Button button = new Button("Press Me");
button.Click += new
System.EventHandler(button_Click);
...
private void button_Click(object sender,
System.EventArgs e)
{
<do whatever you want for a pressed button>
}
Bill Campbell, UMB
Attributes
For marking up your program
[Serializable]
class BankAccount
{ ...
}
[Flags, Serializable]
public enum FileAttributes
{
ReadOnly = 0x0001,
...
Encrypted = 0x4000
}
You can define your own
They can have arguments
Your program can act
upon them at run time
Bill Campbell, UMB
Common Language Runtime (CLR)





Visual Basic
C++
JScript
 CLR (JIT)  native
code
C#
(others)
CLR a model
Bill Campbell, UMB
Common Type System
Your language can talk to all the
others so long as it supports:
bool
char
float
double
short
int
long
byte
Bill Campbell, UMB
ulong
CLR Entities

Assemblies are logical collections of
program parts (classes, interfaces, etc.)
• Contain ALL the metadata required for an
application (so it doesn't have to go in
registries)
• One assembly can be physically captured by
several (.exe or .dll) files
• Support versioning
• Can operate under one of several publishing
policies (eg bug fixes vs. new versions)

Namespaces are purely logical
Bill Campbell, UMB
CLR Implementation

CLR has a real assembly language
assembly P -ildasm -ilasm P 



CLR is a beautiful target for compilers
Implemented using a "just in time"
compiler
Generational garbage collector
Bill Campbell, UMB
How to learn about this stuff





Internet
Good books (Microsoft Press)
Download the MS Framework SDK
Borrow Visual Studio .net under the
msdnaa program here at umb (You must
be a student and adhere to the licensing
agreement.)
Take one of my summer courses: CS650
or CS697a (both limited in size)
Bill Campbell, UMB