Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Structure of a C# Program
Basic Input/Output Operations
Recommended Practices
Compiling, Running, and Debugging
Hello, World
The Class
The Main Method
The using Directive and the System
Namespace
Demonstration : Using Visual Studio
to Create a C# Program
using System ;
class Hello
{
public static void Main( )
{
Console.WriteLine("Hello, World");
}
}
// 기본 폼 – 콘솔응용 프로그램
using System ;
namespace helloworld
{
class Class1
{ static void Main (string[ ] args)
{ //
// TODO: Add code to start application here
//
}
}
}
{ N, M }
• N : the Parameter Number
• M : Field Width and Justification
Console.WriteLine("{0,10}", 99);
" 99"
Console.WriteLine("{0,-10}", 99);
"99 "
Console.WriteLine(99);
Console.WriteLine("99");
Console.WriteLine("The sum of {0} and {1} is {2}", 100,
200, 100+200);
Console.WriteLine("Left justified in a field of width 10:
{0,-10}", 99);
Console.WriteLine("Right justified in a field of width 10:
{0,10}", 99);
Note : use backward slash (\) to turn off the special
meaning of the character.
"\{" = {, "\\" = \, "@\\a\b" = \\a\b
{ N : Format M }
• N : the Parameter Number
• M : Field Width and Justification
Formatting
• C : currency
• D : decimal integer
• E : exponential notation
• G : either Fixed point or Integer
• N : the number with embedded commas
• X : the number by hexadecimal notation
C as currency
D as a decimal integer
F as a fixed-point value
Commenting Applications
Generating XML Documentation
Demonstration : Generating and view XML
documentation
Exception Handling
using System;
public class Hello
{
public static void Main( string [ ] args)
{
try { Console.WriteLine (args[0]) ; }
catch (Exception e) {
Console.WriteLine("Exception at {0}",
e.StackTrace);
}}}
/? Or /help /warnaserror
/out /target
/main /checked
/optimize /doc
/warn /debug
Execution
Runtime Engine
Security Checks
2021년 11월 2일 C# 프로그래밍 29
C# Keywords