您的位置:首页 > 其它

13接口登记案例 把对象赋值给接口

2016-12-06 17:18 387 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _13接口登记案例
{
class Program
{
static void Main(string[] args)
{
//需求:person house 汽车 财产 都需要登记

//把对象赋值给接口
//类似于 把子类赋值给父类
Dengji(new Person());
Dengji(new House());
Dengji(new Car());
Dengji(new Money());

}
//写一个函数,实现登记(传入接口)
static void Dengji(IDengji dj)
{
dj.Dengji();
}

}

internal interface IDengji
{
void Dengji();
}

class Person : IDengji
{
public void Dengji()
{
Console.WriteLine("人要登记");
}
}

class House : IDengji
{
public void Dengji()
{
Console.WriteLine("房子需要登记");
}
}

class Car : IDengji
{
public void Dengji()
{
Console.WriteLine("汽车需要登记");
}
}

class Money : IDengji
{
public void Dengji()
{
Console.WriteLine("财产要登记");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐