初识第二篇

2018-10-30  本文已影响7人  青木川_

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace 初识第二课矩形

{

    class Rectangel

    {

        double lenth;

        double width;

        //成员变量

        public void Acceptdetails()

        {

            lenth = 4.5;

            width = 3.5;

        }

        public double GetArea()

        {

            return lenth * width;

        }

        public void Display()

        {

            Console.WriteLine("长度:{0}",lenth);

            Console.WriteLine("宽度:{0}", width);

            Console.WriteLine("面积:{0}",GetArea());

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

            Rectangel r = new Rectangel();//new 一个对象

            r.Acceptdetails();//初始化变量

            r.Display();//显示变量并调用计算面积的方法或者成为属性

            Console.ReadLine();

        }

    }

    //class关键字用于声明一个类

    //c#中的注释以/*开始,*/结束。

    //单行注释//开始

    //变量是类的属性用于储存数据。

    //函数是指执行一系列任务的语句。类的成员函数是在类内声明的。

    //标识符的声明规则;

    /*

    1.标识符必须以字母,数字,@开始。

    * 2.标识符的第一个字符不能是数字。

    * 3.标识符不能包含任何嵌入的空格或者符号。

    * 4.标识符不能是c#关键字,除非前面有个@前缀。

    * 5.不能与c#的类库名相同。

    * 6.标识符必须区分大小写,大写字母和小写字母被认为是不同的字母。

    * get  set被称为上下文关键字

    */

    /*变量分为几个类型:

    * 1.值类型。 可以直接分配给一个值。他们是从类System.ValueType派生。int,float,char,他们分别储存数字,浮点数,和字符。

    * 2.引用类型。

    * 3.指针类型。

    * 4.如果需要得到一个类型或变量的精确尺寸,可以使用sizeof方法

    */

}   

上一篇 下一篇

猜你喜欢

热点阅读