C#是一个现代的、通用的、面向对象的编程语言
C# 文件的后缀为 .cs
using System;
	//using 关键字用于在程序中包含 System 命名空间
namespace HelloWorldApplication
    //一个 namespace 里包含了一系列的类。HelloWorldApplication 命名空间包含了类 HelloWorld。
{
   class HelloWorld
   {
      static void Main(string[] args)
      {
         /* 我的第一个 C# 程序*/
         Console.WriteLine("Hello World");
    //WriteLine 是一个定义在 System 命名空间中的 Console 类的一个方法。该语句会在屏幕上显示消息 "Hello World"。
         Console.ReadKey();
    //针对 VS.NET 用户的。这使得程序会等待一个按键的动作,防止程序从 Visual Studio .NET 启动时屏幕会快速运行并关闭。
      }
   }
}
C# 是大小写敏感的
与 Java 不同的是,文件名可以不同于类的名称
在任何 C# 程序中的第一条语句都是:
using System;
using 关键字用于在程序中包含命名空间。一个程序可以包含多个 using 语句
class 关键字用于声明一个类
注释
多行注释:以 /* 开始,并以字符 */ 终止
单行注释:用 ‘//‘ 符号表示
文档注释:用 ‘///‘ 符号表示
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();
        }
    }
}
/*
其运行结果应为:
Length:4.5
Width:3.5
Area:15.75
*/
成员变量
变量是类的属性或数据成员,用于存储数据。在上面的程序中,Rectangle 类有两个成员变量,名为 length 和 width。
成员函数
函数是一系列执行指定任务的语句。类的成员函数是在类内声明的。我们举例的类 Rectangle 包含了三个成员函数: AcceptDetails、GetArea 和 Display。
实例化一个类
在上面的程序中,类 ExecuteRectangle 是一个包含 Main() 方法和实例化 Rectangle 类的类。
标识符
标识符是用来识别类、变量、函数或任何其它用户定义的项目。在 C# 中,类的命名必须遵循如下基本规则:
原文:https://www.cnblogs.com/shumild/p/15174054.html