• C#中通过类来继承两个接口,父类实例化接口中的方法,子类继承父类,调用方法


    实现了父类继承接口,父类实例化接口的方法,子类继承父类,子类调用父类的方法直接使用

    代码如下:

        using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace sortAndArea
    {
    
        
        public interface Sort
        {
              List<int> sort();
        }
    
    
    
        public interface Area
        {
            long area();
        }
    
    
    
         abstract  class CoustomMath : Sort, Area
        {
             public CoustomMath()
             {
              // public  List<int> list = new List<int> { };
             }
    
            public List<int> list = new List<int> {  };     //使用泛型
            public  int l = 0;
    
           
    
            public List<int> sort()
            {
                l = list.Count;
                int temp = 0;
                //Console.WriteLine(l);             
                for (int i = 0; i < l ; i++)         //排序
                {
                    for (int j = i+1; j < l; j++)
                    {
                        if (list[i] > list[j])
                        {
                            temp = list[i];
                            list[i] = list[j];
                            list[j] = temp;
                        }
                    }
                }
                return list;
            }
    
            public long area()
            {
                long sum = 0;
                for (int k = 0; k < l; k++)
                {
                    sum += list[k];
                }
                long r = sum;
                long area =(long) Math.PI * r * r;    //求面积
    
                return area;
            }  
            
        }
    
         class Program : CoustomMath
        {
             public List<int> list = new List<int> { };
    
    
    
             public Program()
             {
                 list = new List<int> { 6, 7, 2, 12, 9, 1, 0 };
                 base.list = list;
                 
             }
    
            
             //Program pp = new Program();
             static void Main(string[] args)
             {
                  //List<int>  list = new List<int> {  };
                 
                 Program pp = new Program();
                 Console.WriteLine("从小到大的排序为:");
                 pp.sort();
                 int l1 = 0;
                 l1 = pp.l;
                 for (int i=0;i<l1;i++)
                 {
                     Console.Write(pp.list[i]+" ");
                 }
                 Console.WriteLine("
    ");
                 Console.WriteLine("求和之后的面积为:");
                 Console.WriteLine(pp.area());
                 Console.ReadKey(); 
             }
    
             
        }
    
    
    }
  • 相关阅读:
    解决安装mysql 到start service出现未响应问题
    【日历】自定义(上下月切换)
    html2canvas 无法渲染网络图片及本地 解决方案
    css 弹性盒子--“垂直居中”--兼容写法
    CSS垂直居中
    window.postMessage 在iframe父子页面数据传输
    小程序 rich-text 处理显示
    前端规范
    CSS技巧(一):清除浮动
    博客地址迁移
  • 原文地址:https://www.cnblogs.com/shoneworn/p/3281642.html
Copyright © 2020-2023  润新知