locked
Connect .cs files RRS feed

  • Question

  • I have 2 .cs files in my app. One i use for algorithm, and the other is Form1.cs. I want to know how can i connect them. When i just add alg.cs and write my code (for example a function MyFunction()) and then in Form1.cs use MyFunction() i get an error.

    Who can help me?

    Monday, May 16, 2011 7:05 PM

Answers

  • Make the class Algorithm and the function MyFunction() public. 
    Amit Govil(amit.govil@hotmail.com)
    • Marked as answer by Aspen VJ Wednesday, May 25, 2011 12:55 AM
    Monday, May 16, 2011 7:18 PM
  •  

    step 1: make the namespace the same OR bring into form1 with "using" like all those other using statements at the top of the code.

    step 2: create and object and access the methods that way OR make the methods public and access them directly.

     

    countryStyle

     

     

    • Proposed as answer by CountryStyle Monday, May 16, 2011 10:45 PM
    • Marked as answer by Aspen VJ Wednesday, May 25, 2011 12:55 AM
    Monday, May 16, 2011 10:45 PM
  • Hi Artxach,

    What do you mean connect the two .cs file? As the 2 .cs file is in your app, I am not sure whether they have the same namespace? And what is the error? To clarify the MyFunction() method as "public static"(I presume that the method is not an instance method ).   

    Here is my test:

    in alg.cs file:

    namespace CSWindowsFormDemo
    {
      class alg
      {
         public static void MyFunction()
        {
          //
        }
      }
    }

    In the Form1.cs file

     public partial class MainForm : Form
      {
        public MainForm()
        {
          InitializeComponent();
    
          alg.MyFunction();
        }
      }


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Aspen VJ Wednesday, May 25, 2011 12:55 AM
    Wednesday, May 18, 2011 7:18 AM

All replies

  • Make the class Algorithm and the function MyFunction() public. 
    Amit Govil(amit.govil@hotmail.com)
    • Marked as answer by Aspen VJ Wednesday, May 25, 2011 12:55 AM
    Monday, May 16, 2011 7:18 PM
  •  

    step 1: make the namespace the same OR bring into form1 with "using" like all those other using statements at the top of the code.

    step 2: create and object and access the methods that way OR make the methods public and access them directly.

     

    countryStyle

     

     

    • Proposed as answer by CountryStyle Monday, May 16, 2011 10:45 PM
    • Marked as answer by Aspen VJ Wednesday, May 25, 2011 12:55 AM
    Monday, May 16, 2011 10:45 PM
  • Hi Artxach,

    What do you mean connect the two .cs file? As the 2 .cs file is in your app, I am not sure whether they have the same namespace? And what is the error? To clarify the MyFunction() method as "public static"(I presume that the method is not an instance method ).   

    Here is my test:

    in alg.cs file:

    namespace CSWindowsFormDemo
    {
      class alg
      {
         public static void MyFunction()
        {
          //
        }
      }
    }

    In the Form1.cs file

     public partial class MainForm : Form
      {
        public MainForm()
        {
          InitializeComponent();
    
          alg.MyFunction();
        }
      }


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Aspen VJ Wednesday, May 25, 2011 12:55 AM
    Wednesday, May 18, 2011 7:18 AM