.Net & c#


Published on

introductiob to .net framework and c#

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

.Net & c#

  1. 1. Alexandre Marreiros, 2011introduction to .Net concepts using c#
  2. 2. Alexandre Marreiros, 2011Agenda Introduction .NET core framework CLR JIT Compiler Managed Code Memmory Management .NET & C# CTS C# language
  3. 3. Alexandre Marreiros, 2011Introduction .NET is a framework that provides a big set of cross plataform technologies A program written in .NET can run in any system that has a implementation of .NET runtime; Includes a virtual machine runtime; Provides a programing API, and a unified language independent development framework;
  4. 4. Alexandre Marreiros, 2011.NET Core Framework Common Language Runtime Framework Class Library
  5. 5. Alexandre Marreiros, 2011.NET Core Framework Common Language Runtime Operating System
  6. 6. Alexandre Marreiros, 2011.NET Core Framework .NET Framework Common Language Runtime Operating System
  7. 7. Alexandre Marreiros, 2011.NET Core Framework C++ C# VB.NET Perl J# F# … Common Language Specification .NET Framework Class Lybrary Common Language Runtime Operating System
  8. 8. Alexandre Marreiros, 2011.NET Core Framework ASP.NET WP7 MVC3 ASP .NET Web Forms Windows Silverlight WCF WWF EF Web Services Forms ADO .NET and XML .NET Framework (Base Class Library) Common Language Runtime Operating System
  9. 9. Alexandre Marreiros, 2011.NET Core Framework CompilesCode in DLL or ExeC#, Vb.NET … Managed Assembly (IL) *more about this at .NET IL assembler, Lindin
  10. 10. Alexandre Marreiros, 2011.NET Core Framework CLR SO IL Code Assembly Compile Runing Program *more about this at .NET IL assembler, Lindin
  11. 11. Alexandre Marreiros, 2011.NET Core Framework Source Language Code Compilation Code Compiler MetadataNative JIT Class ExecutionCode Compiler Loader *more about this at .NET IL assembler, Lindin
  12. 12. Alexandre Marreiros, 2011.NET Core Framework Source code VB C# C++ Compiler Compiler Compiler MSIL Assembly Assembly Assembly Common Language Runtime JIT Compiler Native Managed Managed Managed Unmanaged code Code CLR Code Code Code Operating System Services *more about this at .NET IL assembler, Lindin
  13. 13. Alexandre Marreiros, 2011.NET Core Framework Type Descriptions Classes Base classes Implemented interfaces Data members Methods Assembly Description Name Version Culture Other assemblies Security Permissions Exported Types *more about this at .NET IL assembler, Lindin
  14. 14. Alexandre Marreiros, 2011.NET Core Framework Assembly Bin folder So GAC *more about this at .NET IL assembler, Lindin
  15. 15. Alexandre Marreiros, 2011.NET Core Framework IL (MSIL or CIL) – Intermediate Language  It is low-level (machine) language, like Assembler, but is Object-oriented CTS is a rich type system built into the CLR  Implements various types And operations on those types CLS is a set of specifications that all languages and libraries need to follow  This will ensure interoperability between languages
  16. 16. Alexandre Marreiros, 2011CLR Operational Layer betwen the .NET app and the operating system; Manages runing code like a Virtual machine  Threading  Memory management  Jit Compiling Code access security  Code can be verified to be granted as type safe  Role base security
  17. 17. Alexandre Marreiros, 2011JIT Compiler Based on the CLR Class loader job, this entity is responsible for transforming IL code in to native code; Compilation ondemand when a method is called
  18. 18. Alexandre Marreiros, 2011Managed Code Code that targets CLR is named as Managed Code Object oriented Type-Safe Cross Language integration Exception Handling Verioning Represented in MSIL
  19. 19. Alexandre Marreiros, 2011Memmory ManagementThe CLR manages memory for managed code  All allocations of objects and buffers made from a Managed Heap (keyword new)  Unused objects and buffers are cleaned up automatically through Garbage Collection *more about this at CLR via C#, Jeffrey Ritcher
  20. 20. Alexandre Marreiros, 2011.NET & C# &
  21. 21. Alexandre Marreiros, 2011CTS Any .NET language have the same datatypes, that are based in CTS rules At Binary Level all modules and elements writen in a .NET language are compatible
  22. 22. Alexandre Marreiros, 2011CTS .Net Types Value Type ReferenceType
  23. 23. Alexandre Marreiros, 2011CTS – Value TypesMost programming languages provide built-in data types, such as integersand floating-point numbers that are copied when they are passed asarguments (that is, they are passed by value). In the .NET Framework, theseare called value type.ValueTypes are always passed by copy between methods and in terms ofmemory management they work based on a stack philosophy.
  24. 24. Alexandre Marreiros, 2011CTS – Reference TypesOnly acesseble by Reference, Are used as na overload to ObjectTypes, Their base class are always the Object Type.Reference types store a reference to the value’s memory address and areallocated on the heap. Reference types can be self-describing types, pointertypes, or interface types. The data type can be determined from values ofself-describing types. Self-describing types are further split into arrays andclass types. The class types are user-defined classes, boxed valuetypes, and delegates.
  25. 25. Alexandre Marreiros, 2011 CTS-Value Types & Ref. Types Value Types ReferenceTypes Demo Value Type vs reference typeExplanation for study proposes http://msdn.microsoft.com/en-us/magazine/cc301569.aspx
  26. 26. Alexandre Marreiros, 2011 CTS-Boxing and Unboxing Demo Boxing and unboxing*Explanation for study proposeshttp://www.codeproject.com/Articles/76153/6-important-NET-concepts-Stack-heap-Value-types-re
  27. 27. Alexandre Marreiros, 2011CTS – Types of strutures .NET defines diferent kinds of Object strutures:  Struct  Interface  Class  Abstract Class  Static Class  Enum
  28. 28. Alexandre Marreiros, 2011CTS – objects inner concepts Field Method Attribute Propertie
  29. 29. Alexandre Marreiros, 2011CTS - Visibility Assembly Private Protected Public
  30. 30. Alexandre Marreiros, 2011CTS - Inheritance Interfaces Class Many Class Just 1 class Inheritance inheritance Class
  31. 31. Alexandre Marreiros, 2011Demo first Console app
  32. 32. Alexandre Marreiros, 2011CTS - DelegatesDelegates in .NET languages such as C# and areakin to function pointers in C++. I have found thatsimply being aware of this pseudonym is extremelyhelpful in understanding delegates. The term helpsus to understand that delegates allow a developerto provide a pointer to a method/function/sub etc.But when would a developer find this to be useful?
  33. 33. Alexandre Marreiros, 2011 CTS - DelegatesDeclaration:public delegate int Comparer(object obj1, object obj2);Delegate event handler: public static int CompareFirstNames(object name1, object name2) Demo Delegates
  34. 34. Alexandre Marreiros, 2011CTS - Events
  35. 35. Alexandre Marreiros, 2011CTS - Events A C# event is a class member that is activated whenever the event it was designed for occurs. I like to use the term "fires" when the event is activated. Anyone interested in the event can register and be notified as soon as the event fires. At the time an event fires, registered methods will be invoked. Events and delegates work hand-in-hand to provide a programs functionality. It starts with a class that declares an event. Any class, including the same class that the event is declared in, may register one of its methods for the event. This occurs through a delegate, which specifies the signature of the method that is registered for the event. The delegate may be one of the pre- defined .NET delegates or one you declare yourself. Whichever is appropriate, you assign the delegate to the event, which effectively registers the method that will be called when theevent fires
  36. 36. Alexandre Marreiros, 2011CTS - EventsDeclare delegate public delegate void Startdelegate()Declare Event public event Startdelegate StartEvent;Register as a EventListner StartEvent += new Startdelegate(OnStartEvent);
  37. 37. Alexandre Marreiros, 2011CTS - Events Demo Event
  38. 38. Alexandre Marreiros, 2011C#Now that you already now the basics of .Net Let’s explore a litle bit c#language
  39. 39. Alexandre Marreiros, 2011C# Simple, modern, general-purpose, object-oriented programming language. Strong type checking, array bounds checking, detection of attempts to use un-initialized variables. Automatic garbage collection.
  40. 40. Alexandre Marreiros, 2011C# Support for internationalization. Suitable for writing applications for both hosted and embedded systems. Low memory and processing power requirements. There are no global variables. Code is compiled as managed
  41. 41. Alexandre Marreiros, 2011C# Compare operators == Equal != Not equal > Greater than >= Greater than or equal to < Less than <= Less than or equal to
  42. 42. Alexandre Marreiros, 2011C# - Decision Methods if( cond ){} else{} switch(s){ case "1": Console.WriteLine("You entered 1"); break; case "2": Console.WriteLine("You entered 2"); break; case "3": Console.WriteLine("You entered 3"); break; default: Console.WriteLine("You entered some other number"); break; }
  43. 43. Alexandre Marreiros, 2011C#-Loops for (x = 1; x <= 5; x++){} while (y <= 5){} Do{} while (y<=5); Foreach(object o in array);
  44. 44. Alexandre Marreiros, 2011C# Other concepts hands on and final considerations Questions?
  45. 45. Alexandre Marreiros, 2011References Books:  CLR via c#, Richter  .Net fundamentals, Don Box  .Net IL assembler, Lindin Visit following web sites:  .NET Framework Home Site – http://msdn.microsoft.com/netframework/  The Microsoft .NET Framework Community – http://www.gotdotnet.com/  Code Project – http://www.codeproject.net/  Mono – Open Source .NET Framework – http://www.go- mono.org/  Rotor – Shared Source .NET CLI – http://msdn.microsoft.com/net/sscli/ Read the news groups:  news://msnews.microsoft.com/microsoft.public.dotnet.framewor k
  46. 46. Alexandre Marreiros, 2011Email: Amarreiros@gmail.comTwitter: @alexmarreirosFeel free to ask