1.83k likes | 2.73k Views
Programming with C# and .NET Outline 1 Demo .NET introduction C# Programming 2 3 .NET Remoting 4 Programming with C# and .NET Demo The Basic Idea C# is the programming language that I am long waiting for, because my bad MFC experience. Question: How to use C# to do
E N D
Programming with C# and .NET
Outline 1 Demo .NET introduction C# Programming 2 3 .NET Remoting 4
Programming with C# and .NET Demo
The Basic Idea • C# is the programming language that I • am long waiting for, because my bad • MFC experience. • Question: How to use C# to do • Image Processing • OpenGL Programming(3D Graphics) • DirectX Programming • SEE DEMO
Programming with C# and .NET .NET
Major Components • CLR • Common Language Runtime • a runtime environment • concept similar to JVM • FCL • Framework Class Library • built on top of the CLR • provide services for modern applications
FCL CLR Windows API Windows Operating System (Windows ME, 98, 2000, XP etc) .NET Framework Overview Applications written in J# .NET, VB .NET, or C#
MSIL • Microsoft Intermediate Language • a CPU independent set of instructions • .NET compliant language compile into MSIL • similar to Java Byte Code • sometimes abbreviated as IL
.NET Visual J# .NET C# VB .NET Compile into MSIL MSIL CLR do this Linux native code Windows native code Mac OS native code Will Support soon Support now Will Support soon
Java Java Java Byte Code JVM do this Linux native code Windows native code Mac OS native code
.NET Compliant Languages • Any language that can be compiled into MSIL is called a .NET compliant language • APL, Pascal, Perl, Python, Scheme, Eiffel, Fortran, Java, Jscript, Haskell, COBAL, RPG, APL, Smalltalk, Component Pascal, Curriculum, Mercury, Oberon, Oz, VB .NET , C#, Visual C++ .NET, Visual J# .NET, …
MSIL Advantages • Portability between OS • .NET compliant language are all compiled into MSIL (portable between OS) and can be further compiled into native OS machine codes by CLR • Language Interoperability • Different languages can communicated easily • MSIL codes from different languages can be linked together to form a program
MSIL MSIL MSIL Interoperability Visual J# .NET C# VB .NET Compile into MSIL linked the MSIL codes CLR generated a single application (native code) Windows native code
Language Interoperability • Rules defined in • Common Type System (CTS) • Common Language Specification (CLS) • Cross-language development • Cross-language Debugging • Cross-language Exception Handling • Cross-language Inheritance
Common Type System (CTS) • To unify the data types • Common data types play an important role in • language interoperability • Types can be of two types • Value Type • Reference Type
.NET vs. Java • Runtime environment • .NET CLR • Java JVM • Intermediate Code • .NET MSIL • Java Java Byte Code • Support • .NET Multiple Languages, Multiple Platform • Java Single Language, Multiple Platform
CLR • Load and execute the C # program • Compile the MSIL into native code • use Just-in-Time (JIT) compilers • Garbage Collection • use Garbage Collector (GC) • Security Management • Exception Handling
Managed vs. Unmanaged Code • Managed Code • executed under the control of CLR, and use • the .NET Framework libraries. • Unmanaged Code • does not execute under the CLR • It is possible for managed and unmanaged • code to work together
FCL • concept similar to MFC for Windows • programming • FCL classes are grouped by namespaces and • exported by assemblies • namespace similar to Java package • assembly similar to .dll
FCL • Some Namespaces in FCL (has hierarchy) • System • System.IO • System.Windows.Forms • System.Drawing • Example: • System.Windows.Forms is located in • System.Windows.Forms.dll
CLR vs. CLI • CLI (Common Language Infrastructure) • CLR vs. CLI • CLI is the rule • CLR is the implementation • your own CLR • You can implement your own CLR according • the CLI
MSIL vs. CIL • CIL (Common Intermediate Language) • MSIL vs. CIL • CIL is the rule • MSIL is the implementation • your own IL • You can implement your own IL according • the CIL
Web Services • ASP .NET • host on IIS server • .NET Remoting • can host on any type of applications
Programming with C# and .NET Windows Programming so easy! C#
Anders Hejlsberg • Creator of • C# • Turbo Pascal • Delphi • Anders studied engineering at the Technical • University of Denmark, previously worked for • Borland, now works for Microsoft.
Special features • Properties • Indexers • Delegates and Events • Operator Overloading • Reflection • Attributes • Formatting • Regular Expression
Pointer • Miscellaneous features • jagged array • foreach loop • Runtime type identification (RTTI) • goto • structure (not the same with C/C++)
1. Simple Console Program link • Visual Studio .NET IDE introduction • C# program overview • System.Console.WriteLine(…); • Build and Run C# program namespace method class
link 2. Rapid Application Development • RAD like Visual Basic and Borland C++ • Builder • concise syntax as Java • event-driven programming style
3. Use Assembly link • classes may be compiled into .exe or .dll, • such files are called assemblies and are the • packaging units of C# • An assembly is composed of four sections • manifest • type matadata • program code (in MSIL format) • resources used by the program
Manifest • contain information about the assembly itself • Type matadata • information about the data types used by the • program • Program Code • stored in MSIL format • Resources used by the program • such as .bmp or .jpg files