SlideShare a Scribd company logo
1 of 2
Examples[edit]
The following is a very simple C# program, a version of the classic "Hello world" example:
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, world!");
}
}
The effect is to write the following text to the output console:
Hello, world!
Each line has a purpose:
using System;
The above line of code tells the compiler to use System as a candidate prefix for types used in the
source code. In this case, when the compiler sees use of the Console type later in the source code,
it tries to find a type named Console , first in the current assembly, followed by all referenced
assemblies. In this case the compiler fails to find such a type, since the name of the type is
actually System.Console . The compiler then attempts to find a type named System.Console by
using the System prefix from the using statement, and this time it succeeds.
The using statement allows the programmer to state all candidate prefixes to use during
compilation instead of always using full type names.
class Program
Above is a class definition. Everything between the following pair of braces describes Program .
static void Main()
This declares the class member method where the program begins execution. The .NET runtime
calls the Main method. (Note: Main may also be called from elsewhere, like any other method, e.g.
from another method of Program .) The static keyword makes the method accessible without an
instance of Program . Each console application's Main entry point must be declared static .
Otherwise, the program would require an instance, but any instance would require a program. To
avoid that irresolvable circular dependency, C# compilers processing console applications (like that
above) report an error, if there is no static Main method. The void keyword declares
that Main has no return value.
Console.WriteLine("Hello, world!");
This line writes the output. Console is a static class in the System namespace. It provides an
interface to the standard input, output, and error streams for console applications. The program calls
the Console method WriteLine , which displays on the console a line with the argument, the
string "Hello world!" .
A GUI example:
using System.Windows.Forms;
class Program
{
static void Main()
{
MessageBox.Show("Hello, world!");
}
}
This example is similar to the previous example, except that it generates a dialog box that contains
the message "Hello, world!" instead of writing it to the console.

More Related Content

What's hot

Setting UIAutomation free with Appium
Setting UIAutomation free with AppiumSetting UIAutomation free with Appium
Setting UIAutomation free with AppiumDan Cuellar
 
Setup web-application-testing-environment
Setup web-application-testing-environmentSetup web-application-testing-environment
Setup web-application-testing-environmentNabarun Roy
 
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIIntro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIBlue Elephant Consulting
 
Rails VUWIT workshop
Rails VUWIT workshopRails VUWIT workshop
Rails VUWIT workshopbreccan
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPressHarshad Mane
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program executionRumman Ansari
 
Codeception presentation
Codeception presentationCodeception presentation
Codeception presentationAndrei Burian
 
Java applets
Java appletsJava applets
Java appletslopjuan
 
Applet execution
Applet execution Applet execution
Applet execution myrajendra
 

What's hot (15)

Setting UIAutomation free with Appium
Setting UIAutomation free with AppiumSetting UIAutomation free with Appium
Setting UIAutomation free with Appium
 
Setup web-application-testing-environment
Setup web-application-testing-environmentSetup web-application-testing-environment
Setup web-application-testing-environment
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIIntro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
 
Appletjava
AppletjavaAppletjava
Appletjava
 
Homework4
Homework4Homework4
Homework4
 
Rails VUWIT workshop
Rails VUWIT workshopRails VUWIT workshop
Rails VUWIT workshop
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
 
Readme
ReadmeReadme
Readme
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
 
What is selenium
What is seleniumWhat is selenium
What is selenium
 
Codeception presentation
Codeception presentationCodeception presentation
Codeception presentation
 
Java applets
Java appletsJava applets
Java applets
 
Applet execution
Applet execution Applet execution
Applet execution
 

Similar to Examples c#

Similar to Examples c# (20)

Basics1
Basics1Basics1
Basics1
 
Cordovilla
CordovillaCordovilla
Cordovilla
 
1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Structure of a C# Program
Structure of a C# ProgramStructure of a C# Program
Structure of a C# Program
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
Tutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng ver
 
Module 2: Overview of c#
Module 2:  Overview of c#Module 2:  Overview of c#
Module 2: Overview of c#
 
The basics of c programming
The basics of c programmingThe basics of c programming
The basics of c programming
 
C# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkC# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net Framework
 
Csharp_Chap06
Csharp_Chap06Csharp_Chap06
Csharp_Chap06
 
Intro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample ProgramIntro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample Program
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4
 
A tutorial on C++ Programming
A tutorial on C++ ProgrammingA tutorial on C++ Programming
A tutorial on C++ Programming
 
overview of c#
overview of c#overview of c#
overview of c#
 
AS TASKS #8
AS TASKS #8AS TASKS #8
AS TASKS #8
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
C# ProgrammingInstructions are as follows.I need to use the Cons.pdf
C# ProgrammingInstructions are as follows.I need to use the Cons.pdfC# ProgrammingInstructions are as follows.I need to use the Cons.pdf
C# ProgrammingInstructions are as follows.I need to use the Cons.pdf
 
C++
C++C++
C++
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 

Recently uploaded

ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 

Recently uploaded (20)

Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 

Examples c#

  • 1. Examples[edit] The following is a very simple C# program, a version of the classic "Hello world" example: using System; class Program { static void Main() { Console.WriteLine("Hello, world!"); } } The effect is to write the following text to the output console: Hello, world! Each line has a purpose: using System; The above line of code tells the compiler to use System as a candidate prefix for types used in the source code. In this case, when the compiler sees use of the Console type later in the source code, it tries to find a type named Console , first in the current assembly, followed by all referenced assemblies. In this case the compiler fails to find such a type, since the name of the type is actually System.Console . The compiler then attempts to find a type named System.Console by using the System prefix from the using statement, and this time it succeeds. The using statement allows the programmer to state all candidate prefixes to use during compilation instead of always using full type names. class Program Above is a class definition. Everything between the following pair of braces describes Program . static void Main() This declares the class member method where the program begins execution. The .NET runtime calls the Main method. (Note: Main may also be called from elsewhere, like any other method, e.g. from another method of Program .) The static keyword makes the method accessible without an
  • 2. instance of Program . Each console application's Main entry point must be declared static . Otherwise, the program would require an instance, but any instance would require a program. To avoid that irresolvable circular dependency, C# compilers processing console applications (like that above) report an error, if there is no static Main method. The void keyword declares that Main has no return value. Console.WriteLine("Hello, world!"); This line writes the output. Console is a static class in the System namespace. It provides an interface to the standard input, output, and error streams for console applications. The program calls the Console method WriteLine , which displays on the console a line with the argument, the string "Hello world!" . A GUI example: using System.Windows.Forms; class Program { static void Main() { MessageBox.Show("Hello, world!"); } } This example is similar to the previous example, except that it generates a dialog box that contains the message "Hello, world!" instead of writing it to the console.