Sunteți pe pagina 1din 18

Introduction to

Outline
 The C# language
 The Common Language Runtime
 The Visual Studio.NET IDE
 Projects and Solutions
 The first C# program- Console
Application
C# Language
 C# is a simple and modern fully object
oriented language
 It is developed by Microsoft.
Why C#
 It is a modern object oriented
programming language.
 Easy to learn.
 Produces efficient programs.
 Can be compiled on a variety of
computer platforms as long it has the
Common Language Runtime.
Common Language Runtime
 The CLR is a framework layer that
resides above the OS and handles
execution of all the .NET applications.
 It is an application virtual machine that
provides services like security, memory
management etc.
The Visual Studio.Net IDE
 The Integrated Development Environment which eases
the development process of .Net applications.
 The IDE provides useful development tools such as;
◦ Keyword and syntax highlighting
◦ Intellisense which automatically completes the syntax
◦ Simple drag and drop support for user interface building
◦ Hot compiler that checks the syntax and notifies of
error
◦ Properties tab that helps set properties of different
controls
◦ Deploying .Net applications over the internet or disk
Projects and solutions
 A project is a combination of an
executable and library files that make an
application.
 A solution is a placeholder for different
logically related projects that make some
application.
C# programs
 When creating a program in C#, follow the
steps below.
 Determine the objectives of the program i.e.
what problem one wants to solve.
 Determine the methods one wants to use in
writing a program e.g. what tools to use,
what information one needs, formulae etc.
 Create the program to solve the problem.
 Run the program to test if it solves the
problem.
Program Structure - Hello World
Application
 A C# program has the following parts.
◦ Namespace declaration
◦ Class
◦ Main Method
◦ Statements and Expressions
◦ Comments
Hello World Application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloWorldApplication
{
class Program
{
static void Main(string [ ] args)
{
Console.WriteLine("Hello"); // method displays
Console.ReadLine(); // prevents console from closing quickly when
program is launched
}
}
}
The using Keyword
 Allows us to access the classes in the
namespace mentioned or includes the
namespace in the program.
using System; // includes system namespace
Namespace
 A namespace is a logical collection of
related classes.
 C# does not allow two classes with the
same name to be used in a program.
The class Keyword
 The class keyword declares a class.
 A class is a combination of data (fields) and
functions (methods) that can be
performed on this data in order to achieve
the solution to a problem.
Console.ReadLine( ); // Console is a class
The Main( ) method
 This is the entry point of a program i.e. a
program starts its execution from the
first line of the main method.
 string [ ] args is a list of parameters that
can be passed to main while executing the
program.
 Main starts with a capital M and the
return type is void.
Comments
 These are used for explaining code in the
program.
 They are ignored by the compiler i.e. not
executed.
 // comments single line statement
 /*…*/ comments block statement or
multiple lines
Interactive application
Console.WriteLine("Enter your name:");
string userName = Console.ReadLine();
Console.WriteLine("Hello {0}" ,userName);
Console.ReadLine();

Substitution parameter: Places the


variable where you want it.
Note
 C# is case sensitive.
 All statements and expressions must end
with a semicolon.
 Program execution starts at the Main.

S-ar putea să vă placă și