接口-配置文件

摘要:
使用System.Threading.Tasks;写入配置文件<配置>使用System.Configuration;使用System.Linq;使用System.Text;使用System.Threading.Tasks;car.Light();car.wheel();Console.ReadLine();

实现功能:通过更改配置文件实现不同的功能

1,创建以下内容

接口-配置文件第1张

 2,ICar接口代码

接口-配置文件第2张接口-配置文件第3张
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 接口配置文件
{
  public  interface ICar
    {
        void wheel();
        void Light();
    }
}
View Code

3,Car代码

接口-配置文件第4张接口-配置文件第5张
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 接口配置文件
{
    public class Car : ICar
    {
        public void Light()
        {
            Console.WriteLine("我有8个灯");
        }

        public void wheel()
        {
            Console.WriteLine("我有四个轮子");
        }
    }
}
View Code

4,Bike代码

接口-配置文件第6张接口-配置文件第7张
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 接口配置文件
{
    public class Bike : ICar
    {
        public void Light()
        {
            Console.WriteLine("我有一个灯");
        }

        public void wheel()
        {
            Console.WriteLine("我有两个轮子");
        }
    }
}
View Code

5,添加引用

接口-配置文件第8张

6,编写配置文件

接口-配置文件第9张接口-配置文件第10张
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
  
  //下面这一部分
  <appSettings>
    <add key="Icar" value="Bike"/>  
  </appSettings>
  
  
</configuration>
View Code

 7,Factory代码

一定要 using System.Configuration;

接口-配置文件第11张接口-配置文件第12张
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
namespace 接口配置文件
{
   public  class Factory
    {
        private static string ICar = ConfigurationManager.AppSettings["Icar"];
        public static ICar ObjectFactory()
        {
            if (ICar=="Car")
            {
                return new Car();
            }
            else 
            {
                return new Bike();
            }
               
        }

    }
}
View Code

8,程序调用

接口-配置文件第13张接口-配置文件第14张
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 接口配置文件
{
    class Program
    {
        static void Main(string[] args)
        {
            ICar car = Factory.ObjectFactory();
            car.Light();
            car.wheel();
            Console.ReadLine();
        }
    }
}
View Code

9,更该一些内容即可

接口-配置文件第15张

 接口-配置文件第16张

免责声明:文章转载自《接口-配置文件》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇AngularJS 指令之 ng-hide/ng-show破解Linux系统开机密码下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

查询(关键字查询,多条件查询)

一、关键字查询 (1)查询一张表,要把表先列出来,显示出查询的表 <table cellpadding="0" cellspacing="0" border="1"> //正常的查看表,前几天刚学习的内容   <tr> <td>代号</td> <td>名称&l...

git 和 repo 常用命令

一、git 1、回退到某个节点   git reset --hard f39043d1c0cd1cda45a4569556758d0c00bf329a    2、查看提交记录   git log   git log -p  查看更改内容   git show 节点号, 查看某个节点的更改内容,如git show f39043d1c0cd1cda45a456...

Webservice返回json数据格式

问题: 我将结果内容用字符串拼接成Json数据并返回的时候,会在结果前面添加xml头部,结果如下。 [plain] view plaincopy <span ><string xmlns="http://tempuri.org/">   {"data":[{"batchId":"B001","produceOrderId":...

Mybatis之批量操作

首先批量操作的优点是:大大的提高查询的效率。 举个简单的例子:如果在程序中遍历来执行sql的话,这种情况就是有多少行数据就要执行多少条sql,这样导致的效率将是非常低。 如下可能需要40s insert into USER (name,age) values ('张三','33'); insert into USER (name,age) values (...

Kubernetes 1.5通过Ceph实现有状态容器

  在上一篇博文,我们通过kubernetes的devlopment和service完成了sonarqube的部署。看起来已经可用,但是仍然有一个很大的问题。我们知道,像mysql这种数据库是需要保存数据而且不能让数据丢失的。而容器恰恰是一旦退出,所有数据都会丢失。我们的mysql-sonar容器一旦重启,那么我们后续对sonarqube做的任何设置都会丢...

WordPress标题函数wp_title()详解

在wp_title()中通常是在页面头部的title元素中。当wp_title()在主页主循环(loop)外时,可以用在模板的任何地方。 用法: 1 <?php wp_title( $sep, $echo, $seplocation ); ?> 参数: $sep (字符串)(可选)显示在文章标题前后的文字信息(如分隔符)。 默认情况下(若分隔...