Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

.NET and C# introduction


Published on

What is .NET?
What is C#?
Language Differences VB + C#
Review of OOP
N-Tier Solution Design
Creating WinForms applications

Published in: Education
  • Be the first to comment

.NET and C# introduction

  1. 1. Developing Windows and Web Applications using Visual Studio.NET<br />Peter Gfader<br />
  2. 2. Agenda<br />About SSWand Presenters<br />Student Introduction<br />Course Overview<br />.NET Overview<br />VS. Net Overview/ Demo<br />Design Patterns<br />Hands on lab<br />
  3. 3. SSW Consulting has 18 years development / consulting experience.<br />Adam Cogan is the Chief Software Architect at SSW<br />1of 3 Microsoft Regional Directors in Australia<br />About SSW<br />
  4. 4. SSA @ SSW<br />Loves C# and .NET (Java not anymore)<br />Specializes in <br />Windows Forms<br />ASP.NET<br />TFS testing<br />Automated tests<br />Silverlight<br />Peter Gfader<br />
  5. 5. Attendance<br />Please initial the sheet next to your name<br />Hands On Lab<br />Please get Peter to initial sheet<br />Homework<br />Certificate <br />At end of 10 sessions<br />Admin Stuff<br />
  6. 6. Name<br />Company<br />Experience<br />IT<br />Programming<br />.NET<br />C# / VB<br />Database<br />Goals for the course<br />Anything else after 9PM<br />Introductions<br />
  7. 7.<br />Part 1: .NET WinForms<br />Overview of .NET & C# basics<br />C# Advanced + Data in Forms<br />Usability - Rules to Better Windows Forms<br />Deployment and Security of Windows Forms<br />Web Services and Threading<br />The 10 Sessions<br />
  8. 8.<br />Part 2: .NET Webforms<br />Overview of ASP.NET Webforms<br />Data in Webforms<br />Usability<br />Rich Web Forms and <br />Other ASP.NET Features <br />Web Security <br />Advanced Topics & Future Technology <br />The 10 Sessions<br />
  9. 9. What is .NET?<br />What is C#?<br />Language Differences VB + C#<br />Review of OOP<br />N-Tier Solution Design<br />Demo: Creating WinForms<br />Session 1: Overview<br />
  10. 10. .NET is the Microsoft Web services strategy to connect information, people, systems, and devices through software<br />Microsoft, beginning 2000 <br />What is .NET?<br />
  11. 11. What is .NET?<br />An application development platform from Microsoft<br />Runtime (Virtual machine)<br />Tools<br />Languages, IDE, …<br />Rapidly develop secure and robust software<br />Web and Windows<br />Full support for object-oriented programming<br />
  12. 12. Compiles to MSIL<br />Represents codeindependent from src<br />Executes MSIL<br />
  13. 13. What is .NET?<br />Language Independence<br />VB<br />C#<br />F#<br />C++<br />IronPython<br />Any language that supports the Common Language Runtime (CLR) Specification<br />
  14. 14. CLR<br />Common<br />Language<br />Runtime<br />= Virtual machine <br />
  15. 15. Tools<br />C:WindowsMicrosoft.NET <br />
  16. 16. 2002 - .Net 1.0 / Visual Studio.NET<br />2003 - .Net 1.1 / Visual Studio 2003<br />2005 - .Net 2.0 / Visual Studio 2005<br />2007 - .Net 3.5 / Visual Studio 2008<br />2008 - .Net 3.5sp1 (added EDMX)<br />2010 - .Net 4.0/ VS.Net 2010 <br />Details on<br />History of .NET and Visual Studio<br />
  17. 17. Interoperability<br />Common Runtime Engine (CLR)<br />Language Independence<br />Base Class Library<br />Simplified Deployment<br />Security<br />Portability<br />Principal Design Features<br />
  18. 18. Over 4500 classes that provides features such as:<br />Data access and connectivity (ADO.NET)<br />User Interfaces (WinForms, WPF)<br />Web Applications (ASP.NET, Silverlight)<br />Network Communication (WCF)<br />Workflow (WF)<br />What is the .NET Framework?<br />
  19. 19. Evolution<br />The whole .NET FX 3.5<br /><br />Only new types in .NET 4<br /><br />.NET Framework<br />
  20. 20. Allows for language independence<br />Memory Management (allocation and de-allocation of memory)<br />Performs automatic garbage collection with the elimination of pointers<br />No more memory leaks (in theory at least!)<br />Exception Handling<br />Security (sandbox from the OS– cannot run malicious code)<br />Converts the IL byte code into runtime code<br />CLR =Common Language Runtime<br />
  21. 21. Main programming language for .NET framework<br />Based on C<br />Object Oriented <br />Built with hindsight <br />Java Very similar to Java<br />C++ Very similar to C++<br />A ‘modern language’ that did not inherit the ‘junk’ from C++ (eg header files, syntax)<br />C# ?<br />
  22. 22. Variable declaration<br /> bool isVeryLong;<br />Variable assignment<br /> isVeryLong = false;<br />Control statements<br />if (yourInput.Length > 10)<br />{<br />isVeryLong = true;<br />}<br />C# Basis<br />
  23. 23. C# 1.0 – First Version <br />C# 2.0 – Everything that didn’t fit in 1.0<br />C# 3.0 – LINQ, functional influence<br />C# 4.0 – Dynamic Programming <br />C# 5.0 … <br />History C# - Anders Hejlsberg <br />
  24. 24. Base Class Library<br />Highly structured via Namespaces:<br />System.Data<br />System.Web<br />System.Windows<br />System.Xml<br />See VS.NET/.NET Framework help for complete breakdown<br />
  25. 25. OOP<br />
  26. 26. Terms - I want you to know<br />#1 Inheritance<br />#2 Encapsulation<br />#3 Polymorphism<br />#4 Abstraction<br /><ul><li>Classes
  27. 27. Objects
  28. 28. Properties
  29. 29. Methods
  30. 30. Events</li></li></ul><li>Class vs. Object<br /><ul><li>Class</li></ul>Defines abstract characterizations of a “thing”<br />Customer<br />Employee<br />Car<br />Blueprint or template<br />Object<br />Instance of a class<br />“Car” has an instance called “petersCar”<br />
  31. 31. Properties<br />Changeable features of objects<br />Eg. „Color“ of a car<br />Methods<br />Actions on an object<br />Eg. Car has a method „Accelerate“<br />Events<br />Let other objects know about an action<br />Eg. Car has an event „DoorOpened“<br />Terms<br />
  32. 32. #1 Inheritance<br />
  33. 33. A "square" is a "shape"<br />#1 Inheritance<br />
  34. 34. A "shape" defines a common property "Color" <br />A "square" inherits the property "Color" <br />
  35. 35. Information hiding<br />E.g.A shape hides internal data<br />1st point<br />2nd point<br />#2 Encapsulation<br />
  36. 36. A „Square" has internal fields like „_side“<br />
  37. 37. Appear as another<br />Be used like another<br />#3 Polymorphism<br />
  38. 38. var shapes = new List<IShapes>() {<br />new Square(“Red"),<br />new Rectangle(“Blue"),<br />new Triangle(“Red")<br />};<br />foreach (var shape in shapes) {<br />Console.WriteLine(shape.Color + ": " + shape.CalcSize());<br />}<br />#3 Polymorphism<br />
  39. 39. Allows inheritance but no instantiation<br />#4 Abstraction<br />
  40. 40. No instance of a "Shape"<br />
  41. 41. Common Type System<br />Reference Types<br />All derive from System.Object<br />Referential Identity <br />Every object created is DISTINCT from any other object created<br />Eg two “People” may have the same name, but will always be two individuals<br /><ul><li>Value Types
  42. 42. derived from System.Valuetype
  43. 43. Int16
  44. 44. int32
  45. 45. Double
  46. 46. Boolean
  47. 47. Float
  48. 48. Eg:
  49. 49. int x = 5;
  50. 50. boolIsEmpty = false;</li></li></ul><li>Boxing is converting a Value Type into a corresponding Reference Type.<br />Unboxing is converting the Reference Type into a Value Type <br />intfoo = 42; // Value type.<br />object bar = foo; // foo is boxed to bar.<br />int foo2 = (int)bar; // Unboxed back to value type. <br />Boxing and Unboxing<br />
  51. 51. VB.NET versus C#<br />
  52. 52. Variables<br />Language Differences<br />' VB<br />DimFavouriteColourAsString = "LightGreen"<br />// C#<br />StringFavouriteColour = "LightGreen";<br />
  53. 53. Methods<br />Language Differences<br />'VB<br />Public Function GetName () As String <br />Public Sub DoSomething()<br />//C#<br />public string GetName() {}<br />public void DoSomething() {}<br />
  54. 54. Events and Methods<br />Language Differences<br />
  55. 55. VB Properties<br />Language Differences<br />PublicPropertyFirstName() AsString<br />Get<br />ReturnpFirstName<br />EndGet<br />Set(ByVal value AsString)<br />pFirstName = value<br />EndSet<br />EndProperty<br />
  56. 56. C# Properties<br />Language Differences<br />private string firstName;<br />public StringFirstName{ get { returnfirstName } set { firstName= value; } } <br />
  57. 57. Automatic Properties Feature<br />public StringFirstName{ get; set;}<br />Notice no internal variable was declared?<br /> It is created by the compiler<br />Saves typing and makes code neater<br />Properties since C# 3.0<br />
  58. 58. Auto Implemented Properties<br />Collection Initializers<br />Named parameters<br />Optional parameters<br />Lambdas<br />Can span statements across multiple lines<br />Auto Implemented Properties<br />Collection Initializers (limited)<br />Named parameters<br />Optional parameters<br />Lambdas (limited)<br />Can span statements across multiple lines<br />.NET 3.5<br />
  59. 59. Auto Implemented Properties<br />Collection Initializers<br />Named parameters<br />Optional parameters<br />Lambdas<br />Can span statements across multiple lines<br />Auto Implemented Properties<br />Collection Initializers<br />Named parameters<br />Optional parameters<br />Lambdas<br />Can span statements across multiple lines<br />.NET 4<br />
  60. 60. Visual Studio 2010<br />
  61. 61. Visual Studio 2010<br />
  62. 62. Windows Forms<br />
  63. 63. A UI Component<br />WinForm – a Window displayed by an application<br />Web Forms are page hosted in a browser<br />What is a Form?<br />
  64. 64. Textboxes<br />Buttons<br />Tool Strip Menu<br />Picture<br />Labels<br />Controls<br />
  65. 65. <ul><li>Reuse a set of controls</li></ul>e.g. Form with <br />Billing Address and <br />Shipping Address<br />Where an address consists of<br />Address line 1 <br />Address line 2 <br />Suburb <br />State<br />Post code<br />User Controls<br />
  66. 66. Most controls have events<br />Examples<br />Clicked<br />TextChanged<br />Closing<br />Event Handlers<br />Can’t control the order the event gets handled<br />Events<br />
  67. 67. "Programming"<br />Able to code in that language<br />"Understanding .NET“ <br />Understanding the .NET Framework and technology<br />"Architecture“ <br />Knowing when and what do and why<br />Architecture vs. Programming<br />
  68. 68. Namespace<br />Dot syntax. E.g. System.Collections<br />Scope<br />Delegates<br />Exception<br />Debugging<br />Useful Terms…<br /><ul><li>Unit Test
  69. 69. Reference (e.g. Component Reference)
  70. 70. Embedded Resource
  71. 71. Project vs. Solution</li></li></ul><li>Compiled binaries that can be understood by the CLR<br />Known in .NET as “Assembly”<br />Assembly contain classes, structures, components, UI components, execution logic<br />Suffixed with extension .dll and named according to Namespace<br />Eg: SSW.Framework.Utilities.dll<br />What is a Library<br />
  72. 72. A design pattern is a general repeatable solution to a commonly occurring problem in software design. <br />Referred to as GoF (Gang of Four, after their authors). <br />Considered the foundation for all other software patterns.<br />This concepts are incorporated in the .Net Framework (eg. The Iterator pattern)<br />Design Patterns<br />
  73. 73. Gang of Four Patterns<br />Creational Patterns<br />Abstract Factory<br />Creates an instance of several families of classes<br />Builder<br />Separates object construction from its representation<br />Factory Method<br />Creates an instance of several derived classes<br />Prototype<br />A fully initialized instance to be copied or cloned<br />Singleton<br />A class of which only a single instance can exist<br /> <br />    <br />
  74. 74. Gang of Four Patterns<br />Behavioral Patterns<br />Chain of Resp.<br />A way of passing a request between a chain of objects<br />Command<br />Encapsulate a command request as an object<br />Interpreter<br />A way to include language elements in a program<br />Iterator<br />Sequentially access the elements of a collection<br />Mediator<br />Defines simplified communication between classes<br />  <br />Memento<br />Capture and restore an object's internal state<br />  <br />Observer<br />A way of notifying change to a number of classes<br />State<br />Alter an object's behaviour when its state changes<br />Strategy<br />Encapsulates an algorithm inside a class<br />Template Method<br />Defer the exact steps of an algorithm to a subclass<br />Visitor<br />Defines a new operation to a class without change<br />
  75. 75. Gang of Four Patterns<br /> Structural Patterns<br />Adapter <br />Match interfaces of different classes<br />Bridge<br />Separates an object’s interface from its implementation<br />Composite<br />A tree structure of simple and composite objects<br />Decorator<br />Add responsibilities to objects dynamically<br />Facade<br />A single class that represents an entire subsystem<br />Flyweight<br />A fine-grained instance used for efficient sharing<br />Proxy<br />An object representing another object<br /> <br />
  76. 76. Enterprise Architecture Patterns<br />Design Patterns representing an entire system/software application<br />Logical layers<br />Areas of concern<br />Gang of Four Patterns<br />
  77. 77. N-Tier Application Simplified<br />
  78. 78. Separate logic and data access from presentation<br />Easier to maintain code <br />Low-coupling<br />Modularity/Re-use business logic<br />Easily add a different UI<br />Web UI<br />Smart Phone UI<br />Team Development<br />Why n-tier?<br />
  79. 79. Keep the users in mind<br />
  80. 80. Keep the users in mind<br />
  81. 81. WPF?<br />
  82. 82. Windows Presentation Foundation<br />Rich Windows Applications<br />Great Architecture + Great Graphics<br />Rapid Prototyping<br />2D, 3D, Vector, Document Flow, Layouts, Composition, etc.<br />WPF in a nutshell<br />
  83. 83. User interface (UI) components. User interface components provide a way for users to interact with the application. They render and format data for display to users, and acquire and validate data that users enter. <br />User process components. To help synchronize and orchestrate these user interactions, it can be useful to drive the process using separate user process components. This avoids hard-coding the process flow and state-management logic in the UI elements themselves, and the same basic user interaction patterns can be reused by multiple UIs. <br />Business components. Business components implement the business logic of the application. Regardless of whether a business process consists of a single step or an orchestrated workflow, your application will probably require components that implement business rules and perform business tasks. <br />Rich Client App Architecture<br />
  84. 84. Business workflows. After the required data is collected by a user process, the data can be used to perform a business process. Many business processes involve multiple steps that must be performed in the correct order and orchestrated. Business workflows define and coordinate long-running, multi-step business processes, and they can be implemented using business process management tools. <br />Business entity components. Business entities are used to pass data between components. The data represents real-world business entities, such as products or orders. The business entities that are used internally in the application are usually data structures, such as DataSets, DataReaders, or Extensible Markup Language (XML) streams, but they can be implemented as custom object-oriented classes that represent the real-world entities your application has to work with, such as a product or an order. <br />Rich Client App Architecture<br />
  85. 85. Application façade (optional). A façade is used to combine multiple business operations into single message-based operation. You might access the application façade from the presentation layer by using a range of communication technologies. <br />Data access logic components. Data access components abstract the logic necessary to access your underlying data stores. Doing so centralizes data access functionality and makes it easier to configure and maintain. <br />Data Helpers/utilities. Implement data helpers for centralizing generic data access functionality such as managing database connections and caching data. You can design data source–specific helper components to abstract the complexity of accessing the database. Avoid adding any business logic to the helper components. <br />Service agents. When a business component must use functionality provided in an external service, you might need to provide some code to manage the semantics of communicating with that particular service. Service agents isolate the idiosyncrasies of calling diverse services from your application, and can provide additional services such as basic mapping between the format of the data exposed by the service and the format your application requires. <br />Rich Client App Architecture<br />
  86. 86. The 10 Sessions<br />Overview of .NET<br />OOP<br />Language Differences<br />n-Tier Application Architecture<br />Demo: Creating WinForms (C#)<br />Summary<br />
  87. 87. Creating a Windows Form Application<br />Opening forms<br />Menus<br />Event handlers<br />User controls<br />Hands ON LAB<br />
  88. 88. The C# tutorial<br />Online videos and training<br />Nice video to OOP<br />More on OOP<br />Resources 1/2<br />
  89. 89. Design patterns in C#<br />Winforms tips and tricks<br />Use controls in Windows Forms!<br /><br /><br /><br />Beginner Developer Learning Center<br />Resources 2/2<br />
  90. 90. 3things…<br /><br /><br />
  91. 91. Thank You!<br />Gateway Court Suite 10 81 - 91 Military Road Neutral Bay, Sydney NSW 2089 AUSTRALIA <br />ABN: 21 069 371 900 <br />Phone: + 61 2 9953 3000 Fax: + 61 2 9953 3105 <br /> <br />