zoukankan      html  css  js  c++  java
  • C#紧耦合的例子

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ClosedCouple
    {
        class Program
        {
            static void Main(string[] args)
            {
                Engine engine = new Engine();
                
                Car  myCar= new Car(engine);
            
                myCar.Run();
                Console.ReadLine();
            }
        }
        class Engine
        {
            public int rpm=0;
            public int gas { get; set; }
            public void Acculate()
            {
                this.gas-=1;
               this.rpm += 1000;
            }
        }
        class Car
        {
            private Engine engine;
            private int Speed;
    
            public Car(Engine engine)
            {
                this.engine = engine;
                this.Speed = engine.rpm / 10;
                
            }
            
           
            public void Run()
            {
                engine.Acculate();
                this.Speed = engine.rpm / 10;
                Console.WriteLine("My speed is{0}",this.Speed);
            }
    
        }
    }
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Review
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] a1 = new int[] { 1, 2, 3, 4, 5 };
                ArrayList a2 = new ArrayList() {1,2,3,4,5 };
    
                Console.WriteLine( Add(a1) );
                Console.WriteLine( Average(a1));
                Console.WriteLine(Add(a2));
                Console.WriteLine(Average(a2)); 
               Console.ReadLine();
            }
    
            static int Add(IEnumerable  a)
            {
                int res = 0;
                foreach (var item in a)
                {
                    res +=(int)item;
                }
                return res;
            }
            static double Average(IEnumerable a)
            {
                int res = 0, count = 0;
                foreach (var item in a)
                {
                    res +=(int) item;
                    count++;
                }
                return res / count;
            }
        }
    }
  • 相关阅读:
    微博回调接口
    vue获取微博授权URL
    生成微博授权URL接口
    微博账号注册
    微博三方登录原理讲解
    使用celery异步发送短信
    celery配置与基本使用
    友情链接
    Linux无线网络设置--wpa_supplicant的使用
    wpa_supplicant介绍与使用
  • 原文地址:https://www.cnblogs.com/1521681359qqcom/p/11421811.html
Copyright © 2011-2022 走看看