110 likes | 120 Views
Distributed Systems. Tutorial 1 - Getting Started with Visual C# .NET. 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
E N D
Distributed Systems Tutorial 1 - Getting Started with Visual C# .NET
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
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.
Hello World application cont. • Select Visual C# Projects on the left and then Console Application on the right. .
Specify the name of your project and enter the location in which to create the project. The project directory will be created automatically by Visual Studio • Click OK and you're on your way!
Class1.cs • using System; • namespace HelloWorld • { • class Class1 • { • static void Main(string[] args) • { • Console.WriteLine("Hello C# World!"); • } • } • }
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, C#.NET World!"); } • }
Namespaces cont. • using System; • class Class1 • { • static void Main(string[] args) { • Console.WriteLine ("Hello, C#.NET World!"); } • } • When the compiler parses theConsole.WriteLine method, it will determine that the method is undefined. • It will search through the namespaces specified with the using directives and will find the method in the System namespace and will compile the code.
Namespaces cont. • Note that using directive applies to namespaces and not to classes • In the example: • System is the namespace • Console is the class • WriteLine is a static method belonging to Console • Therefore the following code would be invalid:
using System.Console; // ERROR: Can’t use a using directive with a class • class Class1 • { • static void Main(string[] args) { • WriteLine ("Hello, C#.NET World!"); } • } • But its possible: • using output = System.Console; //alias • output.WriteLine(“Hello, C#.NET World”);
Skeleton • using <namesplace> • namespace <your optional namespace> • class <your class> • { • public static void Main() • { • // TODO: Add code to start application here } • } • Notice that the angle brackets denote where you need to supply information.