1 / 16

Distributed Systems (236351)

Distributed Systems (236351). Tutorial 1 - Getting Started with Visual Studio C# .NET. Staff. Lecturer: Assoc. Prof. Roy Friedman. Teaching Assistant: Noam Mori. Email: noam@cs.technion.ac.il Office: 325. Office hours: Wednesday 13:30-14:30. Phone: 04-829-4307. 2. Course Info.

jbegay
Télécharger la présentation

Distributed Systems (236351)

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. Distributed Systems (236351) Tutorial 1 - Getting Started with Visual Studio C# .NET

  2. Staff Lecturer: Assoc. Prof. Roy Friedman. Teaching Assistant: Noam Mori. Email: noam@cs.technion.ac.il Office: 325. Office hours: Wednesday 13:30-14:30. Phone: 04-829-4307. 2

  3. Course Info • Home page: http://webcourse.cs.technion.ac.il/236351 • Three mandatory programming assignments. • Requirements: • Working knowledge of Java / C# • Basic knowledge of OOP concepts • Basic knowledge of network concepts (sockets, protocols) • No textbook, look at the home page for manuals, tutorials and additional resources

  4. C# • Designer: Anders Hejlsberg (Microsoft) • Designer of Turbo Pascal, Visual J++, Delphi (Borland) • C Dynasty: Play on Words • C++ increment C by one. • C# the musical note half tone above C • Yet another curly bracket programming language • Grouping: {} • Statements terminated by ";" • C operators: ++ % != += && & ^, >>, ?: … • C like control: • if () … else … • for (…; …; …) … break … • while (…) … continue … • do … while (…) • switch (…) … case … default

  5. Hello World application • Development in Visual Studio is organized around solutions, which contain one or more projects. For this tutorial, we will create a solution with a single C# project. • Creating a New Project • In the Visual Studio .NET environment, select File | New | Project from the menu.

  6. Hello World application cont. • Select Visual C# Projects on the left and then Console Application on the right.

  7. Hello World application cont. • Specify the name of your project, location in which to create the project and the name of your solution. The project directory will be created automatically by Visual Studio • Click OK and you're on your way!

  8. Class1.cs using System; //Namespace namespace project_name { class Program { static void Main(string[] args) { Console.WriteLine("Hello World"); } } }

  9. Namespaces • Namespaces are used to define scope in C# applications • Multiple source code files can contribute to the same namespace • The using directive permits you to reference classes in the namespace without using a fully qualified name class Class1 { static void Main(string[] args) { System.Console.WriteLine("Hello World"); } }

  10. C# Design Principles • Closer to Java than to C++. • Programmer Protection: • Static Typing • Strong Typing • Array Bounds Checking • Garbage Collection • Check against using uninitialized variables • Better Java? • Developed by Microsoft • Compiles to the CLR "Common Language Interface" • Support for "unsafe" features, including pointers.

  11. Object Oriented Purity • Global Variables? No. • All variables are defined in functions/classes. • Global Routines? No. • All routines (functions) are defined in classes. • Non OO Types? No. • Even primitive types belong in the OO hierarchy. • Preprocessor? Yes.

  12. Value/Reference Semantics • Value Types • Simple types: char, int, float, … • Enum types • Struct types • Reference Types • Classes, Interfaces, Delegates publicenum Color {Red, Blue, Green} public struct Point { public int x, y; }

  13. Inheritance Hierarchy • Classes: • Single Inheritance • Common root: System.Object • Unextendable classes: denoted by keyword sealed • Static classes:denoted by keyword static • No non-static members • No instances • Interfaces: • Multiple Inheritance hierarchy • May be implemented by classes and structs • Structs: • No inheritance • May implement interfaces

  14. Accessibility • Five Levels • public Unlimited access • protected This class and all subclasses • private This class only • internal • protected internal • Default Levels • namespace public • enum public • class private • interface public • struct private • others internal

  15. Class/Struct Member Kinds • Instance Constructors: similar to C++/Java constructors • Finalizer: Syntax as C++ destructor; semantics as Java finalizer. • Static Constructors: similar to Java static initializers • Constants: value computed at compile time • implicitly static • Instance Readonly Fields: with readonlykeyword • initialized by constructor / static constructor • Instance Fields: like Java/C++ • Static Fields: with static keyword • Static Readonly Fields: Initialized by static constructor only • Methods & Static Methods: like Java/C++ • Indexers: array access implemented by methods • Properties (and static properties): field access implemented by methods

  16. Properties • Property: a field implemented with methods • Varieties: read only, write only, read-write • Contextual keywords: get, set, value publicstruct Window {publicintn_read = 0;private string title; public string Title { // read-write property get { // property getter methodn_read++; return title; }set { // property setter method if (title == value)// implicit parameterreturn; title = value; redraw(); } } … { Window w = new Window("Initial Title"); Console.WriteLine(w.Title);// incrementn_read w.Title = "My Title"; // redraw

More Related