locked
linking a functions.cs file to form1.cs RRS feed

  • Question

  • I decided to made another .cs file (function.cs) to perform all the functions of my program instead of very long code page in form1.cs.  Now I had added function.cs into the resources folder but when I try to build it gave me an error that say
            The type or namespace name "Calculator" could not be found (are you missing using
            directive or an assembly reference?)

    for the line
           private Calculator calc;

    "Calculator" is a class in the function.cs

    I want to ask, where should I add the directive of assemble reference to link the 2 .cs files?

       
    Monday, June 11, 2007 3:06 PM

Answers

  • In your function.cs file, is there a namespace specified?  In other words, do you have something like this:

     

    Code Snippet

    namespace someNamespaceName

    {

        public class Calculator {

            ...

        }

    }

     

     

    Whatever the namespace is, you must put a using directive at the top of any code file that needs to use the classes in this file.  So for this example, at the top of the form1.cs file, you would have

     

    Code Snippet

    using someNamespaceName;

     

     

    Then you could use the classes, etc. in form1.

     

    Hope this helps

     

    Chris

    Monday, June 11, 2007 9:25 PM
  • Ok, I fixed my own problem, I now felt kind of stupid

    When adding a resource file to the project, in the properties section of function.cs by default the build action is set to "none", I just had to change that to "compile" and it is off and running.
    Wednesday, June 13, 2007 8:53 PM

All replies

  • In your function.cs file, is there a namespace specified?  In other words, do you have something like this:

     

    Code Snippet

    namespace someNamespaceName

    {

        public class Calculator {

            ...

        }

    }

     

     

    Whatever the namespace is, you must put a using directive at the top of any code file that needs to use the classes in this file.  So for this example, at the top of the form1.cs file, you would have

     

    Code Snippet

    using someNamespaceName;

     

     

    Then you could use the classes, etc. in form1.

     

    Hope this helps

     

    Chris

    Monday, June 11, 2007 9:25 PM
  • I though I could just use the same namespace for both files so I have

    namespace Time
    {
        codes
    }

    in both function.cs and form1.cs, I will try it with different namespaces and use the "using" keyword when I get home later tonight

    thanks
    Tuesday, June 12, 2007 6:59 PM
  • Ok, I fixed my own problem, I now felt kind of stupid

    When adding a resource file to the project, in the properties section of function.cs by default the build action is set to "none", I just had to change that to "compile" and it is off and running.
    Wednesday, June 13, 2007 8:53 PM