cpsc 481 tutorial 4
play

CPSC 481 Tutorial 4 Intro to Visual Studio and C# Brennan Jones - PowerPoint PPT Presentation

CPSC 481 Tutorial 4 Intro to Visual Studio and C# Brennan Jones bdgjones@ucalgary.ca (based on previous tutorials by Alice Thudt, Fateme Rajabiyazdi, and David Ledo) Announcements I emailed you an example showing how the evolved


  1. CPSC 481 – Tutorial 4 Intro to Visual Studio and C# Brennan Jones bdgjones@ucalgary.ca (based on previous tutorials by Alice Thudt, Fateme Rajabiyazdi, and David Ledo)

  2. Announcements • I emailed you an example showing how the evolved prototype and walkthrough should be presented in your portfolio. • Please look through this and refer to it while you’re putting together your portfolios. • Your assignment deadline is now Oct. 13 @ 10am.

  3. Visual Studio • Visual Studio is installed on the lab machines • You may download Visual Studio onto your machine for free here • Use your IT/webmail account and password to access MSDN • Install it after downloading

  4. Setting Up SVN Accounts • For those who want an SVN account, go to the CPSC help desk (just outside our tutorial room) and ask for one. • OR email CPSC Help Desk: cpschelp@ucalgary.ca • Request for an SVN account • Include members’ IT account usernames or all usernames you wish to have access to it • State it is for your CPSC 481 group project

  5. SVN and Visual Studio We won’t go over this in tutorial, but here are some resources that can help you: 1. AnkhSVN: http://grouplab.cpsc.ucalgary.ca/cookbook/index .php/VisualStudio/Subversion 2. VisualSVN: https://www.visualsvn.com/ 3. TortoiseSVN: http://tortoisesvn.net/visualstudio.html

  6. Starting a Project

  7. Starting a Project click

  8. Starting a Project click

  9. Starting a Project click

  10. Starting a Project change

  11. Workspace

  12. Workspace coding area

  13. Workspace solution explorer

  14. Workspace run your program

  15. Hello World!

  16. Hello World! click to create a breakpoint

  17. Hello World!

  18. Hello World! call stack and variables

  19. Hello World! debug functions: run, pause, stop, restart

  20. By now, you should know… • Where to download and how to install Visual Studio • How to get SVN accounts • How to create a new project in Visual Studio • Basic features of the workspace • How to make a console application • How to use the debugger

  21. Intro to C# Coding Sources/Materials: • https://msdn.microsoft.com/en-us/library/kx37x362.aspx • https://msdn.microsoft.com/en- us/library/aa288436(v=vs.71).aspx

  22. C# Naming Conventions • Every language has its own naming conventions: • E.g., Java uses camelCasing, while C# uses camelCasing for variables and PascalCasing for methods. int myInteger; public void ReturnResults (){ … } • A lot of people like to call instance variables (or fields) starting with an underscore: int _myInteger • Interfaces always start with an I (e.g., ICloneable )

  23. Basic C# Syntax • Comments work similar to Java: // This is a single-line comment /* This is a multi-line comment */ /// This is how you describe methods /** (This is how you describe methods in Java) */

  24. Basic C# Syntax • Access modifiers public – accessible anywhere private – only accessible within the class or struct protected – only accessible within the same hierarchy internal – only accessible by the same assembly

  25. Properties • A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field. • Also called accessor methods. • Properties are public methods. • Properties enable a class to expose a public way of getting and setting values, while hiding implementation or verification code.

  26. Properties class TimePeriod { private double seconds; public double hours { get { return seconds / 3600; } set { seconds = value * 3600; } } } • A get property accessor is used to return the property value. • A set accessor is used to assign a new value. • The value keyword is used to define the value being assigned by the set accessor. • Properties that do not implement a set accessor are read only.

  27. class Program { static void Main() { TimePeriod t = new TimePeriod(); // Assigning the Hours property causes the 'set' accessor to be called. t.Hours = 24; // Evaluating the Hours property causes the 'get' accessor to be called. System.Console.WriteLine("Time in hours: " + t.Hours); } } // Output: Time in hours: 24

  28. Foreach Loop using System.Collections; ArrayList list = new ArrayList(); list.Add(1); list.Add(2); foreach (int i in list) { int j = i; } If you use generic containers (e.g., ArrayList), casting is implicit, unlike Java where you have to explicitly cast.

  29. Inheritance A class can inherit a base class and also implement one or more interfaces. public class ChildClass : InterfaceName public class ChildClass : ParentClass public class ChildClass : ParentClass, IInterface1, IInterface2 …

  30. Prototype Iteration Based on your walkthrough and the problems you have identified, create updated designs for your prototype that incorporate your solutions. • This exercise does not have to be integrated into your portfolio • It will help you for your later implementation • Try to address all identified problems

  31. Next Week • Intro to Assignment 2 (phase 2 of your projects) • Intro to WPF (interface building)

Recommend


More recommend