Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a class in my code 1

Status
Not open for further replies.

GabeC

Programmer
Apr 17, 2001
245
US
I know this must be a very easy answer but I just can't figure it out.

I am developing a web application using VS.Net and C#. I under stand how to use other System objects such as database communication.
Code:
using System.Data.SqlClient;
Now I have written my own class. and VS.Net created the
Code:
namespace GabeC

My class is called ComFuncs. I have a ComFuncs constructor, and a
Code:
public string isOpen(int myVariable)
function.

What I am having trouble understanding is how I use this class and function from my default.aspx.cs page.
Thanks,

Gabe
 
You need to instantiate a copy of your class:
Code:
ComFuncs MyComFuncs = new ComFuncs();
And then to call your method:
Code:
String Result = MyComFuncs.isOpen(42)
A way to remember things like this is to think of the class as a cookie cutter that stamps out (instantiates) objects that you can use.

Chip H.
 
chiph,

Thank you for your reply.

I do understand how to use a class in the fashion you descibe.

What I don't understand is how VS.Net and C# know where to find ComFunc. For example, I use VB 6.0 quite a bit and if I write a dll called ComFuncs, before I can use it (early bind it anyway) I need to add it as a reference to the project. In C#, before I can use ADO I need to add something like
Code:
using System.Data.SqlClient;
at the top of the class.

Here is what I am trying to do. I want to create an object that handles all my database work for me so I can use it in multiple applications. If I create a dll or class (which should I be doing?) in a project of its own, how do I use it in my other projects?

I guess I assume that since
Code:
System.Data.SqlClient;
is a system object VS.Net knows where to find it.

Does this make any sense at all? If not I will try to explain myself better.

Thanks,

Gabe
 
In your visual studio project window, expand the "References" section. Right-click, and select Add | Reference. Once you've done that, you can then insert the "Using blah.blah" statement at the top of your code.

Chip H.
 
Thank you. I knew it had to be something simple. I have a couple of books on C# and have read through the MSDN. I guess everyone assumes that you should know this so they don't waste space by stating it. Very similar to VB if you know what you are doing.

Thanks,

Gabe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top