Vac*_*ano 2 c# interface automatic-properties
这就是我今天在编码中看到的好奇心.
以下是示例代码:
public class SomeClass
{
public IUtils UtilitiesProperty { get; set; }
}
public interface IUtils
{
void DoSomething();
}
public class Utils : IUtils
{
void DoSomething();
}
Run Code Online (Sandbox Code Playgroud)
编译好了.
什么是UtilitiesProperty?它是一个Util?如果不止一个班级实施了IUTil怎么办?它会在编译失败吗?
Mar*_*ell 13
它给你一个之前没有任何价值(或者更确切地说,它有价值null).如果你为它分配一个Utils引用,那么是:它是a Utils,通过IUtils接口公开.你只能提供它null或实现的东西IUtils.
| 归档时间: |
|
| 查看次数: |
452 次 |
| 最近记录: |