面向对象例子:创建一个c#控制台程序ooexample,在其中编写一个bluecat类,在bluecat中定义相应的属性和方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ooexample
{
    public class BlueCat//定义BuleCat类
    {
        private string cat_name;//私有成员变量
        private string cat_color;
        private int cat_age;
        public void set(string _name,string _color,int _age)
        {
            cat_name = _name;
            cat_color = _color;//设置肤色 等
            cat_age = _age;
        }
        public void CatShow()
        {
            Console.WriteLine("乳名:{0},肤色:{1},年龄:{2}",cat_name,cat_color,cat_age);
        }
        public void LikeEat(string something)
        {
            Console.WriteLine("我喜欢吃{0}",something);
        }
    }
    
    class CatTest
    {
        static void Main(string[] args)
        {
            BlueCat littlecat = new BlueCat();//用new将BlueCat实例化得到littlecat
            littlecat.set("英国小蓝蓝", "蓝色", 6);
            littlecat.CatShow();
            littlecat.LikeEat("鱼");
            Console.ReadKey();

        }
    }
}

猜你喜欢

转载自blog.csdn.net/laizhuocheng/article/details/89401687