C# 使用其他代码 [英] C# using others code

查看:23
本文介绍了C# 使用其他代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这里下载了一个 C# 区间树集合类类 http://intervaltree.codeplex.com/SourceControl/list/changesets -> 右侧 -> 下载.

Iv'e downloaded a C# interval tree collection class class from here http://intervaltree.codeplex.com/SourceControl/list/changesets -> Right hand side -> Download.

但是我无法在 Microsoft Visual C# 2010 Express(也运行 C# XNA)上打开整个项目,因为

However I can't open the whole project on my Microsoft Visual C# 2010 Express (that also runs C# XNA) because

此版本的应用程序不支持解决方案文件夹

Solution folders are not supported in this version of the application

此外,我只想在我自己的单独项目中单独使用该类.

Also I just want the class to use separately in my own seprate project.

我试图将三个重要的看似文件Interval.csIntervalNode.csIntervalTree.cs 复制到我的项目中,但这产生了编译错误

I tried to copy the three important seeming files Interval.cs, IntervalNode.cs and IntervalTree.cs into my project but this generated the compile error

没有处理这种文件类型的导入器

There are no importers which handle this file type

我还尝试将这三个文件的内容复制并粘贴到我的项目中,将它们封装到自己的命名空间中,并且有很多代码.我不得不稍微重新安排一些使用,但遇到了一个问题,可能它希望 PowerCollections .dll 和 .pcb 文件作为 using Wintellect.PowerCollections; 原因

I've also tried to copy and paste the contents of the three files into my project, encapsulating them into there own namespace as well as there was a lot of code. I had to rearange some of the usings a little but have run into the problem that possibly it wants PowerCollections .dll and .pcb files as using Wintellect.PowerCollections; causes

找不到类型或命名空间名称Wintellect"(您是否缺少 using 指令或程序集引用?)

The type or namespace name 'Wintellect' could not be found (are you missing a using directive or an assembly reference?)

我不知道如何继续,或者我是否在做正确的事情来让这门课正常工作.

I'm not sure how to continue or if I'm doing the right thing at all in how to get this class to work.

推荐答案

将库添加到您的解决方案

将 IntervalTreeLib 目录复制到您的 solution 目录中.然后,右键单击您的解决方案,并添加现有项目.将其指向 IntervalTreeLib 中的 IntervalTreeLib.csproj,然后单击打开.这应该将 IntervalTreeLib 项目添加到您的解决方案中.

Copy the IntervalTreeLib directory into your solution directory. Then, right-click your solution, and add existing project. Point it at IntervalTreeLib.csproj in IntervalTreeLib, and click Open. That should add the IntervalTreeLib project to your solution.

您的项目中添加对库的引用

Add a reference to the library in your project

然后,在您的项目中,添加对 IntervalTreeLib 项目的引用:- 右键单击​​引用文件夹,然后添加引用.单击项目"选项卡,然后选择IntervalTreeLib".

Then, in your project, add a reference to the IntervalTreeLib proejct: - Right click the References folder, and Add Reference. Click the Projects tab, and select IntervalTreeLib.

使用代码中的类

要在源代码中使用库中的类,您需要添加:

To use classes from the library in your source then, you need to either add:

using IntervalTreeLib;

void Foo() {
    IntervalTree<int, int> tree = new ...
}

或者,用他们的全名来称呼他们:

Or, refer to them by their full name:

IntervalTreeLib.IntervalTree<int, int> tree = new ...

这篇关于C# 使用其他代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆