reusing a class

T

TomC

For starters - apologies for a bit of cross-posting. I posted this in
another forum, but hours later I noticed that that forum doesn't
appear to get much traffic. Then I remembered this one, so I figured
I'd try again here

I'm coming from a Java background and teaching myself C#. I figured
out how to create libraries in C# and use them in my other projects.

Now I'd like to figure out if I can reuse a class in a different way.

Let's say that I create an instantiable class Foo in namespace
Foobar. Foobar creates an executable, not a library. At some later
time, I'm working on some other project, in some other namespace and
it occurs to me that my old Foo class would work perfectly to solve a
problem, but I foolishly didn't put it in a library when I first
created it.

Obviously, I could recreate Foo in a library, and reference that
library in my new project. But can I reference it in its existing
class without having to make a library?

I tried doing this sort of thing the same way I referenced the class
library .dll, but it didn't seem to work. But I don't know if that
means it can't be done, or if I'm just doing it the wrong way.

Thanks for any help!
 
P

Pavel Minaev

[...]
Obviously, I could recreate Foo in a library, and reference that
library in my new project.  But can I reference it in its existing
class without having to make a library?
I tried doing this sort of thing the same way I referenced the class
library .dll, but it didn't seem to work.  But I don't know if that
means it can't be done, or if I'm just doing it the wrong way.

You should be able to add the .exe as a reference to your project.

Unless he is using .NET 1.x, in which case it would explain why he's
unable to do that.

Granted, it would seem weird to see anyone still having just that, and
not 2.0+ these days... but who knows.
 
R

Redbeard

To Pavel - I am using an older version of C# - VS 2005 - but I'm not
sure what version of .NET that uses. Maybe that it the problem.

To Peter - I agree that redoing is the better option. I just wanted
to know what is and isn't possible. At this point, I'm just playing
and learning. The code I'm writing is all very trivial, beginner-
level stuff. Heck, I literally wrote a Foo class in a Foobar
namespace!

To both - thanks for replying.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top