首页 > Windows开发 > 详细

c#学习02

时间:2020-11-18 19:16:05      阅读:32      评论:0      收藏:0      [点我收藏+]

string方法的一些函数作用

技术分享图片

 

技术分享图片

 

 

 2.继承演示

-子类

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp1 
{
    /// <summary>
    /// 胡萝卜类:继承与蔬菜类。在这里继承是这样写的“:”
    /// </summary>
    class Carrot : Vegetables
    {
        public static void Main(string[] args) {
            Carrot carrot = new Carrot();
            carrot.effect();//调用的父类的方法
            carrot.rhizome();//调的子类的方法
            carrot.Vitamin = "abcdefghijklmnopqrstuvwxyz";//给父类赋值
        }

        /// <summary>
        /// 隐藏基类方法
        /// </summary>
        public new void rhizome()
        {
            Console.WriteLine("细小根茎类植物");
        }
    }
}

 

-父类

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp1
{
    /// <summary>
    /// 蔬菜类
    /// </summary>
    class Vegetables
    {
        /// <summary>
        /// 维生素
        /// </summary>
        private string _vitamin;

        public string Vitamin { get => _vitamin; set => _vitamin = value; }

        public void effect() {

            Console.WriteLine("多吃有益健康");
        }

        public void rhizome() {

            Console.WriteLine("根茎类植物");
        }
    }
}

 

c#学习02

原文:https://www.cnblogs.com/li-yan-long/p/14001567.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!