c#学习02

string方法的一些函数作用

c#学习02

 

c#学习02

 

 

 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

上一篇:Your Composer dependencies require the following PHP extensions to be installed: pcntl


下一篇:WPF 如何引入外部样式