C#note 01: inside a c# program

using Directives and Namespaces

The first lines in the code editor contain using directives listing several .Net Framework namespaces. A namespace is a way of grouping classes ad structs together in a way that limits their scope and avoids name conflicts with other classes and structs. When you create a program in Visual C# Express, a namespace is automatically created for u. To use classes from other namespaces in your program, you must specify them with a using Directive. The most commonly used .Net Fraework namespaces are listed by default when you create a new application. If you use classes from other namespaces in the class library, you must add a using directive for that namespace to the source file. 

 

Comments 

Comments are useful for including notes to yourself or other programmers.

The characters // convert the rest of the line to a comment. You can also comment a block of text by placing it between the characters /* and */.

 

Classes 

The C# language uses classes to package code: all executable C# code must be contained in a class. 

 

Main()

The C# program must contain a Main method, in whic hcontrol starts and ends. The Main method is where you create objects and execute other methods. The Main method is a static method that resides inside a class or a struct. 

 

Console Input and Output

C# console programs generally use the input/output services provided by .Net Framework Console class. 

The WriteLine method displays its string parameter on the commad-line window followed by a new line. The WriteLie method is very useful, and you will use it a lot if you are writing console applications. 

WriteLine can display strings:   

Console.WriteLine("Hellow World!");

WriteLine can also dispaly numbers:

int x = 42; 

Console.WriteLine(x);

If you need to display several items, use {0} to represent the first item, {1} the second item, and so on, like this:

int year = 1066; 

string battle = "Battle of Hastings";

Console.WriteLine("The {0} took place in {1}.", battle, year);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值