Adding a Class Reference to a C# Windows Forms

I have created a class in a seperate file and I want to use that class in my WindowsForm file, how can I reference the class in my WindowsForm file.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ravi SinghSenior Software EngineerCommented:
Hi, assuming your using Visual Studio .NET and the class is compiled into a DLL then you have to reference the DLL file by going to Project --> Add Reference --> Browse. You then have to refer to the class in your code by specifying its full namespace, e.g.:

ClassNameSpace.ClassName object = new ClassNameSpace.ClassName();

or you could add a using directive at the top of the file to include the namespace, then you can simply refer to the class using its name.

If its just a .cs file then you can add that file into your project by going into Project --> Add Existing Item and again, use the same method above to refer to it in your code.
Ravi SinghSenior Software EngineerCommented:
Sorry, don't call your object reference "object" like I did in my example, its a class in the framework!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tsmolskowAuthor Commented:
It is a cs file, and I have added it to the project from the solution, but I'm not sure what to do next, can you give me some code example.
once you have declared the instance you can use the methods with dot notation so.....

ClassName obj = new ClassName();

obj.MethodName(Arg1, Arg2);

for methods returning values....

string str = obj.MethodName(Arg1, Arg2);

hope this helps.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.