C#代码段的一些基础概念

C#代码段名词基础概念

public enum Color {red,yellow,green}
    class Apple
    {
        public Color color;
        public int weight;
        public string shape;
    }
    class Program
    {
        static void Main(string[] args)
        {
            //1.实例化对象
            Apple apple01 = new Apple();
            //2.字段的赋值
            apple01.color = Color.green;
            apple01.weight = 200;
            apple01.shape = "圆形";
            //3.字段的赋值
            Console.WriteLine("ap01的颜色是{0}...", apple01.color);
            Console.ReadKey();
        }
    }

  :Class,如 class Apple,苹果是类,指一类东西;
  对象:Apple apple01,指一个苹果对象apple01;
  对象具有自己的特性,在面向对象编程中,我们把描述该对象的变量称为字段,字段的作用和变量是一样的

猜你喜欢

转载自blog.csdn.net/weixin_43492764/article/details/84024215