471,348 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

New to C# - basic question

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
Aug 1 '08 #1
6 895
On Thu, 31 Jul 2008 23:28:01 -0700, Paolo
<Pa***@discussions.microsoft.comwrote:
[...]
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
Aug 1 '08 #2
On Aug 1, 1:35 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
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
Aug 1 '08 #3
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" wrote:
On Thu, 31 Jul 2008 23:28:01 -0700, Paolo
<Pa***@discussions.microsoft.comwrote:
[...]
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
Aug 1 '08 #4
Chris: thanks. Presumably I can include my new class library with the 'using'
statement.

"Chris Dunaway" wrote:
On Aug 1, 1:35 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
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
Aug 1 '08 #5
On Fri, 01 Aug 2008 16:49:00 -0700, Paolo
<Pa***@discussions.microsoft.comwrote:
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 don't even recall off the top of my head whether a managed DLL _has_ the
same requirements that a regular Windows DLL does (entry point, unload
function, etc.) But yes, if you set the project type correctly (whether
by selecting the correct project type when you create it, or by changing
the output type in the project properties), you'll get a DLL that you can
then reference from other projects.
I'll test the code in a 'normal' app first then.
That should be fine. Though, it's so easy to set up a DLL in VS, I think
you might as well start with your project as a DLL, and reference it in a
test application.

Pete
Aug 2 '08 #6
On Aug 2, 3:52*am, Paolo <Pa...@discussions.microsoft.comwrote:
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").
Aug 2 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by pauldepstein | last post: by
9 posts views Thread by Malcolm | last post: by
4 posts views Thread by Ramesh | last post: by
5 posts views Thread by Aussie Rules | last post: by
4 posts views Thread by MikeB | last post: by
3 posts views Thread by Scott Stark | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.