C#使用别人的代码 [英] C# using others code
问题描述
我从这里下载了一个C#间隔树集合类类 http://intervaltree.codeplex.com/SourceControl/列表/更改集 - >右侧 - >下载。
但是我无法打开我的Microsoft Visual C#2010 Express的整个项目因为
此版本的应用程序不支持解决方案文件夹
我只想让类在我自己的seprate项目中单独使用。
我试图复制三个重要的看似文件 Interval.cs
, IntervalNode.cs
和 IntervalTree.cs
进入我的项目,但这生成编译错误
没有处理此文件类型的导入器
< blockquote>
我也试图将三个文件的内容复制并粘贴到我的项目中,将它们封装到自己的命名空间以及有很多代码。我不得不重新使用一些使用,但遇到了问题,可能它想要PowerCollections .dll和.pcb文件作为
使用Wintellect.PowerCollections;
导致
无法找到类型或命名空间名称Wintellect(是否缺少using指令或程序集引用?)
我不知道如何继续,或如果我做正确的事情在如何让这个类工作。
解决方案将库添加到解决方案
IntervalTreeLib目录放入您的解决方案目录。然后,右键单击您的解决方案,并添加现有项目。在IntervalTreeLib中将它指向
IntervalTreeLib.csproj
,然后单击打开。这应该将IntervalTreeLib项目添加到您的解决方案中。
在项目中添加对库的引用 b
然后,在您的项目中,添加对IntervalTreeLib项目的引用:
- 右键单击References文件夹,并添加引用。点击项目标签,然后选择IntervalTreeLib。
使用代码中的类
那么,您需要使用IntervalTreeLib添加:
void Foo(){
IntervalTree< int,int> tree = new ...
}
IntervalTreeLib.IntervalTree< int,int> tree = new ...
Iv'e downloaded a C# interval tree collection class class from here http://intervaltree.codeplex.com/SourceControl/list/changesets -> Right hand side -> Download.
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.
I tried to copy the three important seeming files
Interval.cs
,IntervalNode.cs
andIntervalTree.cs
into my project but this generated the compile errorThere are no importers which handle this file type
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;
causesThe 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.
解决方案Add the library to your solution
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
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.
Use the classes in your code
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屋!