How to use a class from one assembly into another

D

Daniela Roman

hello,

I want to create a class in a library:

public class GetHello
{
private string aa = "Hello world";
public GetHello()
{
//
// TODO: Add constructor logic here
//
}
public string GetContent()
{
return aa;
}
}

Then I create a simple project and I want to use the GetContent to return
the string.
What I did was to add a reference to the dll created by the library class,
from the Projects tab.
then I create an object:
MyData_Object myObj = new MyData_Object();

trying to use myObj, it does not see the method I created earlier:
GetContent

Thank you
 
M

Mattias Sjögren

Daniela,
public class GetHello [...]
MyData_Object myObj = new MyData_Object();

trying to use myObj, it does not see the method I created earlier:
GetContent

So is the class called GetHello or MyData_Object?


Mattias
 
M

Michael Nemtsev

Hello Daniela,

Have u pointed "using" statement with the namespace where your class locate?

DR> I forgot to mention:
DR>
DR> namespace MyData_Object
DR>
DR> {
DR>
DR> }
DR>
DR> DR>---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
J

Jianwei Sun

MyData_Object myObj = new MyData_Object();

You can only create an object of a class, not a namespace.

J.W.
 
D

Daniela Roman

Thanks
I got the problem, I need to use the namespace in the USING reference and
then the class will be seen entirely.
Is this the approach in N-tier architecture? I mean to create each layer in
a library and then make references to them?

Thank you
 
K

Kevin Spencer

What you need to do is to include the *Project* for the class library in the
Solution for any application that wants to use it. You can include a project
in as many Solutions as you like. I have a single class library Project that
is included in every Solution that I have written. After including the
Project in the Solution, create a reference to the *Project* in the other
Project. Visual Studio will manage the rest.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Shooter
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.
 

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