新建一个c#文件
代码
namesapce相当于import ,后面+项目名+包名;没有分号
public static void Main(string []args) Main大写
Console.Write(“fff”);
Console.Read();//没有这行黑框直接没了
using System;
namespace helloworld1.test1
{
class hello
{
public static void Main(string []args)
{
Console.Write("fff");
Console.Read();
}
}
}
面向对象例子,基本和java没有区别
using System;
namespace RectangleApplication
{
class Rectangle
{
// 成员变量
double length;
double width;
public void Acceptdetails()
{
length = 4.5;
width = 3.5;
}
public double GetArea()
{
return length * width;
}
public void Display()
{
Console.WriteLine("Length: {0}", length);
Console.WriteLine("Width: {0}", width);
Console.WriteLine("Area: {0}", GetArea());
}
}
class ExecuteRectangle
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();
r.Acceptdetails();
r.Display();
Console.ReadLine();
}
}
}