introduction to net c and visual studio
play

Introduction to .Net, C#, and Visual Studio January 16, 2008 - PowerPoint PPT Presentation

Introduction to .Net, C#, and Visual Studio January 16, 2008 Administrative 1 From Java to C# 2 Tools 3 1/23 Coordinates Time: Wednesdays, 10-11am Place: 140 FisherBennett Hall Instructor: Jeff Vaughan Office Hours: Tuesdays


  1. Introduction to .Net, C#, and Visual Studio January 16, 2008

  2. Administrative 1 From Java to C# 2 Tools 3 1/23

  3. Coordinates Time: Wednesdays, 10-11am Place: 140 Fisher–Bennett Hall Instructor: Jeff Vaughan Office Hours: Tuesdays 2:00-3:00, 514 Levine Hall Website: http://www.seas.upenn.edu/~vaughan2/cis399-005/ 2/23

  4. Goals Learn C# Core Language Generics .Net library . . . Practice good software engineering Good design Clean code Source control Documentation . . . 3/23

  5. Problem Sets and Grading Course grade will be based entirely on problem set grades 5 Problem Sets Emphasis on writing code First four will ask you to do specific tasks Last will be an open ended project Policies Code must compile with Visual Studio Express 2008 Late Policy: -25% per day. Cheating: Unpleasant for all involved. 4/23

  6. Administrative 1 From Java to C# 2 Tools 3 5/23

  7. Java and C# share many features Similar syntax, object model, runtime model, etc. Today: Learn basic C# features by analogy to Java. Throughout the semester: Learn advanced features of C#. 6/23

  8. Java: Hello World package greeting ; class Hello { public s t a t i c void main ( String [ ] args ) { System . out . p r i n t l n ( GetText ( ) ) ; } p r i v at e s t a t i c String GetText ( ) { return " Hello World " ; } } 7/23

  9. Translating Hello World (I) / / Java package declaration package greeting ; / / C# namespace namespace Greeting { . . . } Namespaces contain classes and other other namespaces. Two different classes (or namespaces) with the same name may coexist in different namespaces. 8/23

  10. Translating Hello World (II) / / Java and C# class Hello { . . . } Basic class declaration look the same in Java and C#. 9/23

  11. Translating Hello World (III) / / Java p r i v at e s t a t i c String GetText ( ) { return " Hello World " ; } / / C# p r i v at e s t a t i c s t r i n g GetText ( ) { return " Hello World " ; } Identical, except that C# treats string as a keyword. 10/23

  12. Translating Hello World (IV) / / Java public s t a t i c void main ( String [ ] args ) { System . out . p r i n t l n ( GetText ( ) ) ; } / / C# s t a t i c void Main ( s t r i n g [ ] args ) { System . Console . Out . WriteLine ( GetText ( ) ) ; } Unlike Java, a C# program’s main method does not need to be public. (By default methods are private.) In both cases, args is the list of strings provided as input on the command line. 11/23

  13. C#: Hello World namespace Greeting { class Hello { s t a t i c void Main ( s t r i n g [ ] args ) { System . Console . Out . WriteLine ( GetText ( ) ) ; } p r i v at e s t a t i c s t r i n g GetText ( ) { return " Hello World " ; } } } 12/23

  14. More Syntax: Inheritance and Interface Syntax class Animal { . . . } / / . Net convention : name i n t e r f a c e s / / using IName format i n t e r f a c e IWarmBlood { . . . } i n t e r f a c e IBackBone { . . . } / / Uniform syntax f o r extending a base / / class and implementing an i n t e r f a c e class Mammal : Animal , IWarmBlood , IBackBone { . . . } More details of class and object system later this semester... 13/23

  15. More Syntax: Arrays / / Declare a new array i n t [ ] myArray = new i n t [ 6 ] ; / / Declare and i n i t i a l i z e an array i n t [ ] myOtherArray = {2 , 4 , 6 , 8 , 10 , 12}; / / I t e r a t e through an array f o r ( i n t i = 0; i < myOtherArray . Length ; i ++) { myArray [ i ] = myOtherArray [ i ] ; } But we will learn about better ways to store data soon. . . 14/23

  16. Administrative 1 From Java to C# 2 Tools 3 15/23

  17. Course Software Visual Studio Express 2008, C# edition, Microsoft’s free compiler. NUnit 2.4.6, A framework for unit testing. Links to both on the course website. 16/23

  18. Creating a console app in Visual Studio 17/23

  19. Creating a console app in Visual Studio 17/23

  20. Creating a console app in Visual Studio 17/23

  21. Visual Studio organizes files into Projects and Solutions Solutions (usually) correspond to file system directories Each solution contains one or more projects Projects contains items: .cs files (which can represent normal objects, winforms, etc...) references (e.g. nunit.framework), linq s to databases xml files... 18/23

  22. NUnit is a tool for automated testing Programmer specify test methods using attributes . NUnit runs these methods and reports if assertions hold. Agile Programming Philosophy: Test every corner case, and run test cases after every time you compile! 19/23

  23. NUnit example (I) NUnit hooks into test code in your project. using NUnit . Framework ; namespace Greeting { [ TestFixture ] public class HelloTester { [ Test ] public void CorrectString ( ) { Assert . AreEqual ( Hello . GetText ( ) , " Hello World " ) ; } } } 20/23

  24. NUnit example (II) Add Nunit.Framework as a reference for your project. 21/23

  25. NUnit example (II) Add Nunit.Framework as a reference for your project. 21/23

  26. NUnit example (III) Run tests from within the Nunit program. 22/23

  27. NUnit example (III) Run tests from within the Nunit program. 22/23

  28. NUnit example (III) Run tests from within the Nunit program. 22/23

  29. NUnit example (III) Run tests from within the Nunit program. 22/23

  30. Problem Set 1 First problem set available online today. Problem set is designed to get you setup for development. Due next Wednesday (1/23). Email your solution to me before class. 23/23

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend