5
Software development
•
.NET software development and execution has many actors
–
languages
–
libraries
–
compilers
–
intermediate language
–
execution engine
6
Languages
•
Many .NET programming languages available
–
C#
–
VB.NET
–
C++
–
etc.
•
Language choice typically based on many factors
–
programmer background
–
problem domain
–
language features
–
corporate mandate
7
Language power
•
All languages can access .NET infrastructure
C#
class Hello
{
static void Main()
{
System.Console.WriteLine("hello");
}
}
VB.NET
Class Goodbye
Shared Sub Main()
System.Console.WriteLine("goodbye")
End Sub
End Class
8
Language interoperability
•
All .NET languages can interoperate
C# calling
VB.NET
class Hello
{
static void Main()
{
System.Console.WriteLine(Greeting.Message());
}
}
Class Greeting
Shared Function Message() As String
Return "hello"
End Function
End Class
9
C#
VB.NET
Language variability
•
Not all .NET languages have exactly the same capabilities
–
differ in small but important ways
class Hello
{
static void Main()
{
int i;
uint u;
}
}
Class Greeting
Shared Sub Main()
Dim i as Integer
End Sub
End Class
signed integer
unsigned integer
signed integer only
10
Common Language Specification
•
Common Language Specification (CLS) defines type subset
–
required to be supported by all .NET languages
–
limiting code to CLS maximizes language interoperability
–
code limited to CLS called CLS compliant
public class Calculator
{
public uint Add(uint a, uint b)
{
return a + b;
}
}
not CLS compliant
to use uint in public
interface of public class
11
.NET Framework class library
Library
•
Extensive set of standard libraries available
–
for wide range of application types
–
called .NET Framework class library
Collections
Web development
Input/Output
Database access
Windows Forms GUI
Networking
XML processing
Threading
Reflection
Debugging
12
Compilation
•
Compilers produce Intermediate Language (IL)
–
IL is not executable
–
similar to assembly language
–
processor independent
C# code VB.NET code <other> code
VB.NET compilerC# compiler <other> compiler
IL IL IL
13
IL
•
C# compiler translates C# source code into IL
C# source
IL
.locals init ([0] class Calc c, [1] int32 sum)
newobj instance void Calc::.ctor()
stloc.0 // c = ptr to new object
ldloc.0
ldc.i4.2 // pass second arg
ldc.i4.4 // pass first arg
callvirt instance int32 Calc::Add(int32,int32)
stloc.1 // sum = retval
Calc c = new Calc();
int sum = c.Add(2, 4);
C# compiler
14
CLR
Execution engine
•
Common Language Runtime (CLR) is the execution engine
–
loads IL
–
compiles IL
–
executes resulting machine code
IL
Runtime
compiler
Execute
machine code
Không có nhận xét nào:
Đăng nhận xét