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

cpsc 481 tutorial 4
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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)

slide-2
SLIDE 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.
slide-3
SLIDE 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
slide-4
SLIDE 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
slide-5
SLIDE 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

slide-6
SLIDE 6

Starting a Project

slide-7
SLIDE 7

Starting a Project

click

slide-8
SLIDE 8

Starting a Project

click

slide-9
SLIDE 9

Starting a Project

click

slide-10
SLIDE 10

Starting a Project

change

slide-11
SLIDE 11

Workspace

slide-12
SLIDE 12

Workspace

coding area

slide-13
SLIDE 13

Workspace

solution explorer

slide-14
SLIDE 14

Workspace

run your program

slide-15
SLIDE 15

Hello World!

slide-16
SLIDE 16

Hello World!

click to create a breakpoint

slide-17
SLIDE 17

Hello World!

slide-18
SLIDE 18

Hello World!

call stack and variables

slide-19
SLIDE 19

Hello World!

debug functions: run, pause, stop, restart

slide-20
SLIDE 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
slide-21
SLIDE 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

slide-22
SLIDE 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)
slide-23
SLIDE 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) */

slide-24
SLIDE 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

slide-25
SLIDE 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.

slide-26
SLIDE 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.
slide-27
SLIDE 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

slide-28
SLIDE 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.

slide-29
SLIDE 29

Inheritance

A class can inherit a base class and also implement

  • ne or more interfaces.

public class ChildClass : InterfaceName public class ChildClass : ParentClass public class ChildClass : ParentClass, IInterface1, IInterface2 …

slide-30
SLIDE 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
slide-31
SLIDE 31

Next Week

  • Intro to Assignment 2 (phase 2 of your projects)
  • Intro to WPF (interface building)