Introduction to -C#.ppt
《Introduction to -C#.ppt》由会员分享,可在线阅读,更多相关《Introduction to -C#.ppt(85页珍藏版)》请在麦多课文档分享上搜索。
1、Introduction to .Net/C#,By Oliver Feb 23, 2011,Outline,Introduction to .NET Introduction to C# Data Type Array Property Flow control Exception handler Hello world and debug,.NET initiative Introduced by Microsoft (June 2000) Vision for embracing the Internet in software development Independence from
2、 specific language or platform Applications developed in any .NET-compatible language Visual Basic.NET, Visual C+.NET, C# and more Supports portability and interoperability Architecture capable of existing on multiple platforms Supports portability,Microsoft .NET,Key components of .NET Web services
3、Applications used over the Internet Software reusability Web services provide solutions for variety of companies Cheaper than one-time solutions that cant be reused Single applications perform all operations for a company via various Web services Manage taxes, bills, investments and more Pre-package
4、d components using Visual Programming(buttons, text boxes, scroll bars) Make application development quicker and easier,Microsoft .NET,Keys to interaction XML (Extreme Markup Language) and SOAP (Simple Object Access Protocol) “Glue” that combines various Web services to form applications XML gives m
5、eaning to data SOAP allows communication to occur easily,Microsoft .NET,Microsoft .NET,RTM: 2002(v1.0) 2003 (v1.1) 2005 (v2.0) 2006 (v3.0) 2007 (v3.5) 2010 (v4.0) ,.NET Framework,.NET Framework Heart of .NET strategy Manages and executes applications and Web services Provides security, memory manage
6、ment and other programming capabilitiesIncludes Framework Class Library (FCL) Pre-packaged classes ready for reuse Used by any .NET languageDetails contained in Common Language Specification (CLS) Submitted to European Computer Manufacturers Association to make the framework easily converted to othe
7、r platformsExecutes programs by Common Language Runtime (CLR),Windows (or other operating oystem),Common Language Runtime (JIT compilation, memory management, etc.),Legacy Software (unmanaged code),Managed Executable,Reusable Managed Components,Common Language Runtime (CLR),Why two compilations? Pla
8、tform independence .NET Framework can be installed on different platforms Execute .NET programs without any modifications to code .NET compliant program translated into platform independent MSIL Language independence MSIL form of .NET programs not tied to particular language Programs may consist of
9、several .NET-compliant languages Old and new components can be integrated MSIL translated into platform-specific code Other advantages of CLR Execution-management features Manages memory, security and other features Relieves programmer of many responsibilities More concentration on program logic,Com
10、mon Language Runtime (CLR),Compilation And Execution,Source Code,Compilation,At installation or the first time each method is called,Code (IL),Metadata,All managed code runs in native machine language However, all managed code is made up of IL and metadata The CLR JIT-compiles the IL and metadata At
11、 execution time Executed directly by CPU Allows for the best of both worlds Code management features Performance of full-speed execution,JIT,GC is a most important part of CLR It manages many objects lifetime. Instead of allocate/delete keywords in C+, objects are automatically deleted when the appl
12、ication no longer needs them. Its Important to build a efficiently application.,Garbage Collector,string s;StraighLine line;s = “dog“; line = new StraightLine(0.5, 2.5);,“dog“,Garbage Collector,CLR will run GC automatically to free all unreachable objects in heap memory which no references remained.
13、,Garbage Collector,object3,a,b, , ,Garbage Collector,object3,a,b, , ,Garbage Collector,GC demo, show GC collect and different result in debug and release mode.,Garbage Collector,GC manages all objects in Heap, but not any objects been allocated on Heap, like: Unmanaged resource, windows handler, DB
14、connection, file handlertherefore, we need use the Dispose pattern to clean up the memory.,Garbage Collector,FileStream fs = new FileStream(“Temp.dat“, FileMode.Create);tryfs.Write(bytesToWrite, 0, bytesToWrite.Length);finallyif (fs != null)(IDisposable)fs).Dispose();,Garbage Collector,GC events not
15、ification have been added in .Net 4.0.,Garbage Collector,CLR will run GC automatically to free all unreachable objects in heap memory which no references remained.The GC is only called by the CLR when heap memory becomes scarce. The GC only can collect manage resources, all unmanaged resources need
16、to be collected by programmer. The GC will reduce memory leak, but not disappeared.,Summary,The .NET Framework Library,Sit on top of the CLR Reusable types that tightly integrate with the CLR Object oriented inheritance, polymorphism, etc. Provide functionality for ASP.NET, XML Web Services, ADO.NET
17、, Windows Forms, basic system functionality (IO, XML, etc.),The .NET Framework Library,Threading,Text,ServiceProcess,Security,Resources,Reflection,Net,IO,Globalization,Diagnostics,Configuration,Collections,Serialization,Remoting,InteropServices,Runtime,Base Framework,.NET Framework is a code executi
18、on platform .NET Framework consists of two primary parts: .NET Class Libraries, Common Language Runtime All CLR-compliant compilers support the common type system Managed code is object oriented Managed code is compiled to and assembly (MSIL) by language specific compiler Assemblies are compiled to
19、native code by JIT compiler,Summary,.NET and C#,.NET platform Web-based applications can be distributed to variety of devices and desktopsC# Developed specifically for .NET Enable programmers to migrate from C/C+ and Java easily Event-driven, fully OO, visual programming language Has IDE Process of
20、rapidly creating an application using an IDE is called Rapid Application Development (RAD),C#,Language interoperability Can interact with software components written in different languages or with old packaged software written in C/C+ Can interact via internet, using industry standards (SOAP and XML
21、) Simple Object Access Protocol - Helps to share program “chunks” over the internetAccommodates a new style of reusable programming in which applications are created from building blocks,Data Types/Arrays,Mapping C# to CTS,Value & Reference Types,ctor Value type always have a default value Reference
22、 type can be null,int x; MyClass obj;,x =0,obj is null,Value & Reference Types,Memory allocation Reference type always allocate in heap Value type always be allocated in a place where its been declared,int x; MyClass obj;obj = new MyClass();,Allocate a variable on stack,Allocate the object on heap,A
23、llocate a variable on stack,Value & Reference Types,Value & Reference Types,Copy,int x; MyClass obj; obj = new MyClass();Int y = x;MyClass objCopy = obj;,deep copy,shallow copy,Value & Reference Types,Memory Disposal Once the method has finished running, its local stack-allocated variable, x, obj, w
24、ill disappear from scope and be “popped” off the stack. GC will automatically deallocate it from the heap some times later. GC will know to delete it, because the object has no valid referee (one whose chain of reference originates back to a stack-allocated object). C+ programmers may be a bit uncom
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- INTRODUCTIONTOCPPT
