Presentation is loading. Please wait.

Presentation is loading. Please wait.

The First C# Program Elements of a C# Program. Exploring the First C# Program // Namespace Declaration using System; namespace HolaMundo { /// /// Summary.

Similar presentations


Presentation on theme: "The First C# Program Elements of a C# Program. Exploring the First C# Program // Namespace Declaration using System; namespace HolaMundo { /// /// Summary."— Presentation transcript:

1 The First C# Program Elements of a C# Program

2 Exploring the First C# Program // Namespace Declaration using System; namespace HolaMundo { /// /// Summary description for Class1. /// // Program start class class Class1 { /* Main begins program execution The main entry point for the application. */ static void Main(string[] args) { Console.WriteLine("Hola mundo"); } } }

3 Comentarios Los comentarios sirven dos funciones : Hace que el código sea más fácil de leer Internamente documentan que hace los enunciados del programa

4 Diferentes tipos de comentarios Comentarios de una solo linea Comentarios de multiples linea Comentarios estilo xml ( extensible markup language)

5 Using directives and namespaces Namespace: A namespace can be seen as a container for some classes in much the same way that a folder on your file system contains files. By putting the classes into namespaces we can group related classes together. If two classes have the same name, by placing them in different namespaces, we avoid the risk of name collisions.

6 Namespaces It is recommended that you define all your classes in a namespace. Every single class in the.net Framework lives inside a namespace..net provides the significant benefit of making available more than 2,000 classes that make up what is called the Framework Class Library(FCL). A class contains code that can be reused, which makes programming easier and faster because you don’t have to reinvent the wheel.

7 namespaces The Console class lives inside the System namespace. This means that its fully qualified name is actually System.Console. The using directive allows making the names of the classes inside the namespace visible outside the namespace in their shorthand form. Ver ejemple con la clase Console

8 Forma general de un programa using System; namespace MyNamespace1 { class MyClass1 { } struct MyStruct { } interface IMyInterface { } delegate int MyDelegate(); enum MyEnum { } namespace MyNamespace2 { } class MyClass2 { public static void Main(string[] args) { } } }

9 Namespaces C# Language programs can consist of one or more files. Each file can contain one or more namespaces. A namespace can contain types such as classes, structs, interfaces, enumerations, and delegates, in addition to other namespaces.

10 Classes C# is an object-oriented language, everything in C# is designed around a class C# doesn’t allow anything to be defined outside of a class. All methods must be defined inside a class.

11 Classes Programs written using C# can use these predefined.NET classes or create their own classes. It is tradition to name the file conaining the class the same name as the class neme, except the file name will have a.cs extention.

12 Classes Console is a built-in class that contains the methods for displaying messages on the screen and getting input from the keyboard. Within the curly braces, you define the class members. A class member is generally either a member method, which performs some behavior of the class, or a data member, which contais a value associated with the state of the class.

13 Main method The Main method is special, it designates the program’s entry point. It must be a static method. This is where the program begins execution

14 methods A collection of one or more statement combined to perform an acton. Methods are similar to functions in C++. Signature and heading

15 Method body- Statements Console.WriteLine(“Hola Mundo”); Console.Write(“ “); Console.Write(“What goes\nup\nmust come\tdown”);


Download ppt "The First C# Program Elements of a C# Program. Exploring the First C# Program // Namespace Declaration using System; namespace HolaMundo { /// /// Summary."

Similar presentations


Ads by Google