New to C# - basic question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UGFvbG8=?=

    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
  • Peter Duniho

    #2
    Re: New to C# - basic question

    On Thu, 31 Jul 2008 23:28:01 -0700, Paolo
    <Paolo@discussi ons.microsoft.c omwrote:
    [...]
    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

    Comment

    • Chris Dunaway

      #3
      Re: New to C# - basic question

      On Aug 1, 1:35 am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.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

      Comment

      • =?Utf-8?B?UGFvbG8=?=

        #4
        Re: New to C# - basic question

        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
        <Paolo@discussi ons.microsoft.c omwrote:
        >
        [...]
        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
        >

        Comment

        • =?Utf-8?B?UGFvbG8=?=

          #5
          Re: New to C# - basic question

          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...@nn owslpianmk.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
          >

          Comment

          • Peter Duniho

            #6
            Re: New to C# - basic question

            On Fri, 01 Aug 2008 16:49:00 -0700, Paolo
            <Paolo@discussi ons.microsoft.c omwrote:
            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

            Comment

            • Pavel Minaev

              #7
              Re: New to C# - basic question

              On Aug 2, 3:52 am, Paolo <Pa...@discussi ons.microsoft.c omwrote:
              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").

              Comment

              Working...