我正在关注此代码示例
我在 Visual Studio Community 2019 for Mac 上。我创建了一个 .Net Core-Class Library 项目并编译以创建程序集文件P1-ProgramStructure.dll
。
我用program2.cs
代码创建了另一个解决方案。请看下面的代码。我重命名.dll
为acme.dll
并将文件复制到其目录中。
类库 - .Net Core 项目
程序1.cs
using System;
namespace Acme.Collections
{
public class Stack
{
Entry top;
public void Push(object data)
{
top = new Entry(top, data);
}
public object Pop()
{
if (top == null)
{
throw new InvalidOperationException();
}
object result = top.data;
top = top.next;
return result;
}
class Entry
{
public Entry next;
public object data;
public Entry(Entry next, object data)
{
this.next = next;
this.data = data;
}
}
}
}
.Net 核心控制台应用程序
程序2.cs
using System;
using Acme.Collections;
class Example
{
static void Main()
{
Stack s = new Stack();
s.Push(1);
s.Push(10);
s.Push(100);
Console.WriteLine(s.Pop());
Console.WriteLine(s.Pop());
Console.WriteLine(s.Pop());
}
}
当我运行项目时,出现错误:
$ dotnet run
Program.cs(15,7):错误 CS0246:找不到类型或命名空间名称“Acme”(您是否缺少 using 指令或程序集引用?)[/Users/csarami/VisStudioProjects/cSharp Projects/Project2- ProjectStructure/Project2-ProjectStructure/Project2-ProjectStructure.csproj]
构建失败。请修复构建错误并再次运行。
确保两个项目具有相同的目标框架
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句