Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# - my first stupid question

C# - my first stupid question

Scheduled Pinned Locked Moved C#
questioncsharp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #1

    All the exmaples I see are making one fat .cs file - what is the equivelant of #include, so I can see the contents of one file from another ? Thanks Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

    J E 2 Replies Last reply
    0
    • C Christian Graus

      All the exmaples I see are making one fat .cs file - what is the equivelant of #include, so I can see the contents of one file from another ? Thanks Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      You don't. C# -- like Java -- doesn't look for dependencies until the linking stage (if you could call it that). main.cs

      using System;

      public class Test
      {
      public Test() { }

      public static void Main(string [] args) {
      Foo f = new Foo();
      f.SayHello();
      }
      }

      foo.cs

      using System;

      public class Foo
      {
      public Foo() { }
      public void SayHello() {
      System.Console.WriteLine("Hello Chrstian!");
      }
      }

      That will work just fine, assuming both files are in the compiling process. James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978

      C 1 Reply Last reply
      0
      • J James T Johnson

        You don't. C# -- like Java -- doesn't look for dependencies until the linking stage (if you could call it that). main.cs

        using System;

        public class Test
        {
        public Test() { }

        public static void Main(string [] args) {
        Foo f = new Foo();
        f.SayHello();
        }
        }

        foo.cs

        using System;

        public class Foo
        {
        public Foo() { }
        public void SayHello() {
        System.Console.WriteLine("Hello Chrstian!");
        }
        }

        That will work just fine, assuming both files are in the compiling process. James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Why might it not work ? I did this last night and still got nowhere. If I create a file and save it, do I need to add it to the project somewhere as well ? Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

        J 1 Reply Last reply
        0
        • J James T Johnson

          Christian Graus wrote: If I create a file and save it, do I need to add it to the project somewhere as well ? Yes, it will have to be added to the project or it won't get compiled. How did you go about creating a file and saving it? If you go through the IDE it should be added to the project for you. How I add a new class: Right click my project in the Solution Explorer, choose Add then Add New xxxxx (class, component, windows form, etc). Ah! Just a shot in the dark, do the namespaces match between your two files? Come to think of it, my example didn't have a namespace for foo.cs :-O If you change the namespace you can let the IDE help you a little, right click on the project and choose Properties, then change the Default Namespace to the base namespace you use. HTH, James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          No, I didn't do it quite like this, but I did it through the IDE. I made sure my namespaces matched, but I'll try it fllowing what you said and see how it goes. Thanks. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

          1 Reply Last reply
          0
          • C Christian Graus

            Why might it not work ? I did this last night and still got nowhere. If I create a file and save it, do I need to add it to the project somewhere as well ? Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

            J Offline
            J Offline
            James T Johnson
            wrote on last edited by
            #5

            Christian Graus wrote: If I create a file and save it, do I need to add it to the project somewhere as well ? Yes, it will have to be added to the project or it won't get compiled. How did you go about creating a file and saving it? If you go through the IDE it should be added to the project for you. How I add a new class: Right click my project in the Solution Explorer, choose Add then Add New xxxxx (class, component, windows form, etc). Ah! Just a shot in the dark, do the namespaces match between your two files? Come to think of it, my example didn't have a namespace for foo.cs :-O If you change the namespace you can let the IDE help you a little, right click on the project and choose Properties, then change the Default Namespace to the base namespace you use. HTH, James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978

            C 1 Reply Last reply
            0
            • C Christian Graus

              All the exmaples I see are making one fat .cs file - what is the equivelant of #include, so I can see the contents of one file from another ? Thanks Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

              E Offline
              E Offline
              Eric Gunnerson msft
              wrote on last edited by
              #6

              If you're compiling as part of the same project, you don't need #include; the compiler can automatically access the classes in all the files that are compiled together. If you're compiling into separate assemblies (aka dlls), you'll need to add the referenced one either to the project or using /r on the command line.

              C 1 Reply Last reply
              0
              • E Eric Gunnerson msft

                If you're compiling as part of the same project, you don't need #include; the compiler can automatically access the classes in all the files that are compiled together. If you're compiling into separate assemblies (aka dlls), you'll need to add the referenced one either to the project or using /r on the command line.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                Thanks - it seems the way I added the file did not make it part of the proejct, I did the exact same thing this morning, but added the class by right clicking in the class view and it all worked fine. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups