002 Introduction To C Sharp
002 Introduction To C Sharp
002 Introduction To C Sharp
Chapter 1
1
Objectives
2
Introduction to C#
C# is an extension of ANSI C
Similar to Java
Microsoft Specific (Sort of)
Technically an ECMA Standard
4
Introduction to C#
5
Introduction to C#
6
First C# Program
7
Create a New Project
8
Select Project Attributes
9
Template for a Console Application
Generated automatically by Visual Studio
10
The Hello World Program
11
Build the Project
12
Run the Program
Click here to run
13
The Hello World Program
14
Possibly Unfamiliar Features
Overview
(Details to Follow)
Namespace
using ... ;
class Program
static void Main (string[] args)
15
Namespace
Helps avoid name conflicts in large projects
Not necessary, or particularly helpful, on small projects
Visual Studio automatically wraps everything with
namespace projectName
{
16
using System;
17
"using" Statements
18
using System
If we delete "using System" we get a compile
time error.
Compiler does not know about class Console.
19
Editor Shows Errors
20
using System
If we prefix Console with the namespace
System, there is no error.
namespace Hello
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello, World!");
In C# everything is in a class.
Unlike C and C++
22
Things to Notice
Note capitalization.
“static” means that the function is associated with the class as a
whole rather than with a specific object.
Like C++.
We never instantiate class Program.
System.Console.Writeline("Hello, World!");
gets a compile error
24
Things to Notice
25
Running Outside the IDE
We have an executable file: Hello.exe
26
Path to the Executable
27
Double Click the .exe File
28
Deploying the Program
Copy Hello.exe to C:
Open Command Prompt window and cd to C:
30
Assignment
Read Chapter 1.
31