我创建了一个类型类库的 C# 项目。之后,我创建了一个包含一个类的文件,并尝试从 ICloneable 类继承。VisualStudio 2017 在名称 ICloneable 下划线表示存在错误。在VisualStudio针对这个问题提供的解决方案中,建议自己创建这个界面。
换句话说,ICloneable 接口不可用/未创建。
文档说这个类默认在命名空间中可用 - using System; 但实际上,对于一个类型项目——一个类库,这个规则是行不通的。因为“系统”命名空间附加到我的文件中。
出于兴趣,我创建了一个控制台项目,并尝试从其中的 ICloneable 接口继承。结果,在这种类型的项目中,界面可用,一切正常。事实证明,整个障碍都在所创建项目的类型中。
如何访问类型项目中的 ICloneable 接口 - 类库?
我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UrlBuilder.Url.Sections.ProductModels.Transport.Cars
{
public class Class1 : ICloneable
{
public Class1 Clone()
{
return new Class1();
}
}
}

UWP 项目从 Windows 10 Fall Creators Update(10.0,Build 16299)开始引入了
ICloneable支持 .NET Standard 2.0的接口。为了 ICloneable 出现 - 在创建新项目时或在现有项目的属性中指定最低版本 16299。