gpt4 book ai didi

c# - 接口(interface)和类之间的区别

转载 作者:太空狗 更新时间:2023-10-29 18:02:22 27 4
gpt4 key购买 nike

<分区>

正如标题所说,我想知道使用这样的类的区别

public class Account
{
public string Username { get; set; }
public string Password { get; set; }
}

像这样使用和界面

public class Account : IAccount
{
public string Username { get; set; }
public string Password { get; set; }
}

public interface IAccount
{
string Username { get; set; }
string Password { get; set; }
}

我真的很困惑,因为我发现接口(interface)毫无用处,因为我只能使用类来完成它所能做的一切,因此,我需要有人为我澄清一些事情。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com