{ 和 } 组成语句块
分号表示一个语句的结束
using System;
public sealed class Hiker
{
public static void Main()
{
int result;
result = 9 * 6;
int thirteen;
thirteen = 13;
Console.Write(result / thirteen);
Console.Write(result % thirteen);
}
}
一个C#的“类/结构/枚举”的定义不需要一个终止的分号。
public sealed class Hiker
{
...
} // 没有;是正确的
然而你可以使用一个终止的分号,但对程序没有任何影响:
public sealed class Hiker
{
...
}; //有;是可以的但不推荐
在Java中,一个函数的定义中可以有一个结尾分号,但在C#中是不允许的。
public sealed class Hiker
{
public void Hitch() { ... }; //;是不正确的
} // 没有;是正确的
总结:C#中类可以为分号,但方法的申明是不能有分号;
转载于:https://blog.51cto.com/5257890/904403