Download presentation
Presentation is loading. Please wait.
1
2. Developing in.NET and C#
2
2 Microsoft Objectives “Microsoft.NET development is based on an underlying framework of tools and classes. These tools and classes are known as the Framework SDK (Software Development Kit).”.NET development options Brief summary of C# Class-based development Component-based development
3
3 Microsoft Part 1.NET development options…
4
4 Microsoft Recall assemblies 1 assembly = 1 or more compiled classes –.EXE represents an assembly with classes + Main program –.DLL represents an assembly with classes Development Tools assembly code.vb code.cs.EXE /.DLL
5
5 Microsoft.NET development There are currently 3 ways to develop assemblies: 1).NET Framework SDK free (100 MB) complete set of command-line tools and docs available for Windows NT, 2000, XP Pro, 2003 http://msdn.microsoft.com/net other platforms? –FreeBSD / Mac OS X via Rotor (i.e. SSCLI) –Linux via Mono project
6
6 Microsoft Development options, cont'd 2) Visual Studio.NET 5-6 CDs, 192 MB RAM (bare minimum) powerful, integrated development environment (IDE) one IDE for all: GUI, web-based, web service, DLLs, etc. this is what 99% of the world uses $$ –MSDNAA reduces cost to $800/year for unlimited access 3) free IDEs #develop, a simplified clone of VS.NET WebMatrix, for building web-based applications
7
7 Microsoft Hello World in C# Here's the source code: /* hello.cs */ public class Startup { public static void Main() { System.Console.WriteLine("Hello World!"); } }//class hello.cs
8
8 Microsoft Why System.Console prefix? In.NET, all code & data must live within a module / class Often nested within namespaces to help organize things –a namespace is really just a named collection Example: System.Console.WriteLine("Hello World!"); Console class WriteLine subroutine System namespace in FCL
9
9 Microsoft Compiling and running To compile C# with Framework SDK, use the C# compiler –open Visual Studio.NET command prompt window to set path –csc is the command-line C# compiler –use /t:exe option to specify console-based EXE as target To run, simply use name of assembly… c:\> csc /t:exe hello.cs Microsoft (R) Visual C#.NET Compiler version 7.00.9466 for Microsoft (R).NET Framework version 1.0.3705 Copyright (C) Microsoft Corporation 2001. All rights reserved. c:\> hello.exe Hello World!
10
10 Microsoft Viewing an assembly with ILDasm IL = Microsoft's Intermediate Language (i.e. generic asm) ILDasm = IL Disassembler c:\> ildasm hello.exe
11
11 Microsoft IL? Very similar to Java bytecodes: –generic assembly language –stack-based –strictly typed –no direct memory addressing –verifiable for safe execution
12
12 Microsoft Part 2 Development on FreeBSD…
13
13 Microsoft Development on FreeBSD Working on FreeBSD is exactly the same! –i.e. same command-line tools as Framework SDK –produces *binary-compatible*.DLL and.EXE files!
14
14 Microsoft Part 3 Brief summary of C#...
15
15 Microsoft C# Case-sensitive Strict type-checking Operator and method overloading Single public inheritance; any number of interfaces All classes inherit from object; classes may be nested Garbage-collected Multiple classes may exist in one file Multiple files may be compiled into one assembly Each assembly typically written in one language When in doubt, think Java!
16
16 Microsoft Part 4 Class-based development…
17
17 Microsoft A customer class Here's the source code for a simple Customer class: /* customer.cs */ public class Customer { public string Name; // fields public int ID; public Customer(string name, int id) // constructor { this.Name = name; this.ID = id; } public override string ToString() // method { return "Customer: " + this.Name; } }//class
18
18 Microsoft Main class Here's the source code for Main, using our Customer class: /* main.cs */ public class App { public static void Main() { Customer c; c = new Customer("joe hummel", 94652); System.Console.WriteLine( c.ToString() ); } }//class
19
19 Microsoft Compiling and running application Compile and run as before… –/out: option specifies name of resulting EXE –in this case we are building monolithic app (single EXE, no DLLs) c:\> csc /t:exe /out:app.exe main.cs customer.cs Microsoft (R) Visual C#.NET Compiler version 7.00.9466 for Microsoft (R).NET Framework version 1.0.3705 Copyright (C) Microsoft Corporation 2001. All rights reserved. c:\> app.exe Customer: joe hummel
20
20 Microsoft Part 5 Component-based development…
21
21 Microsoft Example Let's rebuild previous app based on components –Customer class ==> DLL –Main class ==> EXE app.exe customer.dll + main.cs customer.cs
22
22 Microsoft Compiling a component Use the C# compiler… –with /t:library option to specify component library as target –csc produces a DLL in this case c:\> csc /t:library customer.cs Microsoft (R) Visual C#.NET Compiler version 7.00.9466 for Microsoft (R).NET Framework version 1.0.3705 Copyright (C) Microsoft Corporation 2001. All rights reserved. c:\> dir *.dll customer.dll
23
23 Microsoft Compiling and running application Compile using C# compiler as before, except… –reference component so compiler can locate Customer class! –reference also stored inside assembly so CLR can locate To run, use name of assembly containing Main… –CLR follows reference to locate DLL c:\> csc /t:exe /out:app.exe main.cs /r:customer.dll Microsoft (R) Visual C#.NET Compiler version 7.00.9466 for Microsoft (R).NET Framework version 1.0.3705 Copyright (C) Microsoft Corporation 2001. All rights reserved. c:\> app.exe Customer: joe hummel
24
24 Microsoft Where are references stored? Within assembly as part of assembly manifest Visible via ILDasm c:\> ildasm app.exe
25
25 Microsoft mscorlib? mscorlib = "ms-core-lib" Core FCL assembly –contains core system classes like string –contains System.Console class for console-based I/O Automatically referenced for us by C# compiler…
26
26 Microsoft Recall CLR-based execution.EXE other FCL assemblies CLR JIT Compiler obj code OS Process Underlying OS and HW Core FCL assembly.DLL obj code All assemblies must be present:
27
27 Microsoft Summary.NET is multi-language –Framework SDK based on C# and VB.NET –lots of other languages available.NET development is component-based –helper classes implemented in one or more DLLs –EXE implemented using helper classes –if (assembly A uses a class from assembly B) then A must reference B!
28
28 Microsoft References Books: –J. Richter, "Applied Microsoft.NET Framework Programming" Web sites: –http://msdn.microsoft.com/nethttp://msdn.microsoft.com/net –MSDNAA: http://www.msdnaa.net/http://www.msdnaa.net/ –Rotor (SSCLI): http://msdn.microsoft.com/net/ssclihttp://msdn.microsoft.com/net/sscli –Mono: http://www.go-mono.com/http://www.go-mono.com/ –Free IDEs: http://www.icsharpcode.net/OpenSource/SD/default.asp http://www.asp.net/webmatrix/ –Anakrino reverse-engineering tool: http://www.saurik.com/net/exemplar/
29
29 Microsoft Lab? Work on lab #1, "Architecture"…
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.