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;
            }
        }
    }
  • 相关阅读:
    hadoop 异常及处理总结-02(小马哥精品)
    Linux环境变量(小马哥推荐)
    Apache Tomcat 8.5 安全配置与高并发优化
    深入理解分布式系统中的缓存架构(上)
    Redis的n种妙用,不仅仅是缓存
    springBoot整合ecache缓存
    Spark Streaming实时处理应用
    Spark 实践
    spark性能调优
    Spark调优
  • 原文地址:https://www.cnblogs.com/1521681359qqcom/p/11421811.html
Copyright © 2011-2022 走看看