1 / 58

C#: Introduction for Developers

Neal Stublen nstublen@jccc.edu. C#: Introduction for Developers. Class Objectives. Develop an understanding of the .NET Framework Gain proficiency using Visual Studio Begin learning the C# programming language Apply object-oriented concepts within the C# language

Download Presentation

C#: Introduction for Developers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Neal Stublen nstublen@jccc.edu C#: Introduction for Developers

  2. Class Objectives • Develop an understanding of the .NET Framework • Gain proficiency using Visual Studio • Begin learning the C# programming language • Apply object-oriented concepts within the C# language • Develop basic Windows Forms applications • Learn basic .NET database concepts

  3. Suggestions • Install Visual Studio • Visual Studio Express 2013 for Windows Desktop • Review each chapter • We won’t necessarily hit every point in class • Bring back questions • Work projects at end of each chapter • Make changes and experiment

  4. Tonight’s Agenda • Overview of .NET • Using Visual Studio • Designing a Form • Object-Oriented Programming • Walk through a simple object example • Apply what we’ve learned • Q&A

  5. Chapter 1Overview of .NET

  6. Windows Applications Windows Application Microsoft Windows OS / Intel Platform Display File System Network

  7. .NET Applications .NET Application (or "Assembly") .NET Framework Class Libraries Common Language Runtime (CLR) Non-Microsoft OS? / Non-Intel Platform? Microsoft Windows OS / Intel Platform Display File System Network

  8. C#, .NET, and Windows .NET "Assembly" (MSIL) C# Source Files C# Compiler CLR .NET "Assembly" (MSIL) "Native" Code

  9. How does C# compare? • VB.NET, F#, Managed VC++ are other .NET languages • They all compile into MSIL assemblies that run on the .NET CLR • They all have their own unique syntax • Java has many similarities • .NET class library instead of the Java support classes • Might be considered a "safer" version of C++.

  10. Chapter 1, Part 2Using Visual Studio

  11. Using Visual Studio • Start Visual Studio • Create a project • Windows Forms for desktop applications • Web Forms for web-based applications • Console applications for the command line • The project represents all or part of an application • A solution is a container for multiple projects

  12. Express Editions • Free Visual Studio versions • http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx

  13. Visual Studio Summary • Project • A collection of files that are used to generate an application or class library • .csproj file extention • Solution • A collection of projects • .sln file extension • Open/close a project/solution • Projects target a specific version of the .NET Framework

  14. Visual Studio Summary • Menus and toolbars can be customized • Solution Explorer manages project files • Form Designer allows us to create and modify forms • Controls are added to a form using the Toolbox • Properties change the appearance and/or function of a form or control

  15. Visual Studio Summary • Tabbed windows can be docked just about anywhere • Tabbed windows can be floating or docked • Tabbed windows can be pinned or hidden • Code Editor allows you to edit source code • Editing window can be split into two panes

  16. Visual Studio Summary • Settings can be imported and exported • We will work with WinForms applications in this class • Projects can be “built” and “run” from within Visual Studio

  17. Chapter 2Designing a Form

  18. Form Design • Add controls from the toolbox • Set control properties • Name, Text • Enabled, ReadOnly, TabOrder, TabStop, TextAlign • AcceptButton, CancelButton, StartPosition • Specify access keys (&) • Specify tab order between controls • Document Outline View • Renaming and saving files

  19. Form Exercise • Create a project named "InvoiceTotal" in your S: folder • Reproduce the following form: • Consider tab order, access keys, etc.

  20. Form Design Summary • Control Toolbox • Tab Order • Properties Window • Name, Text • Enabled, ReadOnly, TabOrder, TabStop, TextAlign • AcceptButton, CancelButton, StartPosition • Access keys (&) • Document Outline View • Renaming and saving files

  21. Chapter 2, Part 2Object-Oriented Programming

  22. Object-Oriented Programming • .NET represents everything as an "object" • What objects can we identify in our InvoiceTotal application? • Forms, Controls

  23. Object-Oriented Programming • Objects are made up of data and a set of functions that act on that data • What data would be stored in the InvoiceTotal form and its controls? • Position, Text • What functions might use that data?

  24. Objects and Classes • An object is represented by a "class" • A class has “member” data • Variables • A class has “member” functions • Methods

  25. A class Definition class Counter { };

  26. A class Definition class Counter { // “class” is a keyword that tells the // compiler we are defining a new type of        // object. };

  27. The class Name (or Type) class Counter {     // “Counter” is the name of the new class // type. };

  28. Member Variables class Counter { private int mValue;     // We declare member variables that will // hold data for the class. };

  29. Member Visibility class Counter { privateint mValue;     // “private” is a keyword that tells the // compiler the class member is not visible // to other objects. };

  30. Member Type class Counter { privateintmValue;     // “int” is a built-in type that tells the // compiler we are defining an integer // value. };

  31. Member Name class Counter { private intmValue;     // “mValue” is the name we will use when // referring to this data member. };

  32. Member Initializer class Counter { private int mValue = 0;     // (Optional) We can assign an initial value to // the data member. };

  33. A class Constructor class Counter {     private int mValue; // Constructor public Counter(int inInitialValue) { mValue = inInitialValue; } };

  34. Constructor Visibility class Counter {     private int mValue; // Constructor public Counter(int inInitialValue) { mValue = inInitialValue; }     // “public” is a keyword that tells the // compiler the class member is visible to // other objects. };

  35. Constructor Name class Counter {     private int mValue; // Constructor public Counter(int inInitialValue) { mValue = inInitialValue; }     // “Counter” repeats the class name, which // tells the compiler we are defining a // constructor for the class. };

  36. Constructor Parameter class Counter {     private int mValue; // Constructor public Counter(int inInitialValue) { mValue = inInitialValue; }     // “intinInitialValue” is a parameter of // the constructor. It is used to set the // initial state of the object. };

  37. Constructor Body class Counter {     private int mValue; // Constructor public Counter(int inInitialValue) { mValue = inInitialValue; }     // The body of the constructor assigns // initial values to any data members of // the class. };

  38. Assignment Operator class Counter {     private int mValue; // Constructor public Counter(int inInitialValue) { mValue = inInitialValue; }     // “=” is an assignment operator that assigns // a value to a variable. };

  39. A class Method class Counter {     private int mValue;     // Constructor     public Counter(int inInitialValue)     {         mValue = inInitialValue;     } // Increment the counter by one. public int Increment() { return ++mValue; } };

  40. Method Visibility class Counter {     private int mValue;     // Constructor     public Counter(int inInitialValue)     {         mValue = inInitialValue;     } // Increment the counter by one. public int Increment() {         return ++mValue; } };

  41. Method Return Type class Counter {     private int mValue;     // Constructor     public Counter(int inInitialValue)     {         mValue = inInitialValue;     } // Increment the counter by one. public int Increment() {         return ++mValue; } };

  42. Method Name class Counter {     private int mValue;     // Constructor     public Counter(int inInitialValue)     {         mValue = inInitialValue;     } // Increment the counter by one. public int Increment() {         return ++mValue; } };

  43. Method Body class Counter {     private int mValue;     // Constructor     public Counter(int inInitialValue)     {         mValue = inInitialValue;     } // Increment the counter by one. public int Increment() { return ++mValue; } };

  44. Prefix/Postfix Operators class Counter {     private int mValue;     // Constructor     public Counter(int inInitialValue)     {         mValue = inInitialValue;     } // Increment the counter by one. public int Increment() { return ++mValue; } };

  45. Code Comments class Counter {     private int mValue; // Constructor     public Counter(int inInitialValue)     {         mValue = inInitialValue;     } // Increment the counter by one.     public void Increment()     {         mValue = mValue + 1;     } }; Counter myCounter = new Counter(0);

  46. Instantiating a class class Counter { ... }; Counter myCounter = new Counter(0); Counter yourCounter = new Counter(10);

  47. Instantiating a class class Counter { ... }; Counter myCounter = new Counter(0); Counter yourCounter = new Counter(10); // “new” is a keyword that tells the compiler // we want to create an instance of the class. // We have created two instances of the Counter // class.

  48. Instantiating a class class Counter { ... }; Counter myCounter = new Counter(0); myCounter.Increment(); // We call a method by using the “.” operator on // a class instance. // All statements are terminated by a semi-colon.

  49. A Closer Look at Our Form

  50. What’s in a form? • A form is defined by a class • Controls on the form are member variables • Event handlers are member functions

More Related