New to C# - basic question

P

Paolo

I want to learn C# initially via console applications. I would like to write
some reusable code that I can 'call' in any application. For example, code to
position the cursor and use the various colour attributes wrapping up some of
the methods of the System.Console library.

What I am not clear on is how I can write these methods in a 'standalone'
file so that I can call them in apps with the 'using' statement. I'm a little
confused as to whether I have to have a Main() method in the file containing
my calleable code.

Sorry if this is basic. I'm using Visual C# Express edition.

Thanks
 
C

Chris Dunaway

You want to make a DLL (the third type in that list). Then you can add a
reference to that DLL in a project in which you want to use the classes in
that DLL.

Look for the project of type "Class Library".

Chris
 
P

Paolo

Peter: thanks for that. So I just write my code and save as a DLL and Visual
Studio does all the rest i.e. saves in the correct file format and adds any
specific DLL statements?

I'll test the code in a 'normal' app first then.

Peter Duniho said:
[...]
What I am not clear on is how I can write these methods in a 'standalone'
file so that I can call them in apps with the 'using' statement. I'm a
little
confused as to whether I have to have a Main() method in the file
containing
my calleable code.

You can create a variety of project types. The three main ones you're
likely to run into are: Windows application; console application; and DLL.

You want to make a DLL (the third type in that list). Then you can add a
reference to that DLL in a project in which you want to use the classes in
that DLL.

Pete
 
P

Paolo

Chris: thanks. Presumably I can include my new class library with the 'using'
statement.
 
P

Pavel Minaev

Chris: thanks. Presumably I can include my new class library with the 'using'
statement.

Not really. "using" statement has nothing to do with libraries as such
- it deals with namespaces. Often a library contains a single
namespace, but it is merely convention (and not a universal one at
that). To reference a library from your program, you need to add a
project reference in Solution Explorer (right-click on "References"
there, and choose "Add").
 

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