面向对象例子:创建一个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();

        }
    }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值