0

I have a partial class defined in two different .cs (Part1.cs, Part2.cs) and I'm not able to call a function in part1.cs from part2.cs. Is it possible to do it ? Both .cs are in the same folder and can use other class in the folder (class1.cs,class2.cs,...)

This is what I'm trying to do:

Part1.cs

namespace MyNamespace
{
    public partial class MainWindow : Window
    {
        public void Two()
        { }

        public void Three()
        { }
    }
}

Part2

namespace MyNamespace
{
    public partial class MainWindow : Window
    {
        public void One()
        {
           Two();
        }
    }   
}
Mr Rubix
  • 1,492
  • 14
  • 27
  • 2
    What happens when you run the code you have? – Rick Liddle Nov 19 '15 at 16:51
  • `i'm not able to call a function in part1.cs from part2.cs` Why do you think so? – Hamlet Hakobyan Nov 19 '15 at 16:52
  • The Name 'Two' does not exist in the current context ! The function is not recognize at all . – Mr Rubix Nov 19 '15 at 16:55
  • Are you sure part1.cs is set to compile? – James Thorpe Nov 19 '15 at 17:00
  • 1
    You're missing a closing brace in Part2. I assume this is just a typo in your simplified version and not something wrong with your actual code. – adv12 Nov 19 '15 at 17:04
  • Maybe they are not supossed to ? But normally functions from the same class can use each others, and functions from different classes can call each other too!? Soe i really dont see why this is not working? Do u have a clue for me Hamlet Hakobyan – Mr Rubix Nov 19 '15 at 17:21
  • 2
    Yes, you can do it. In fact, doing this exact thing is a big reason partial classes exist: you can have one side created using code generation, and the other side hand-written. They can then work together without having to modify any generated code. What people are saying is that there's some other problem here: you should include the *exact* error(s) that you're getting in the post. – 31eee384 Nov 19 '15 at 17:26
  • Both part are compiling without any error, the problem happend when i try to use the function. The problem is not the closing brace, typing mistake – Mr Rubix Nov 19 '15 at 17:29
  • Are you compiling from within Visual Studio? Or are you using the command-line C# compiler? If the latter, are you compiling both files in the same step? – adv12 Nov 19 '15 at 17:35
  • I just try to recreate all the files from scratch and now it's working fine ? I really don't understand ! I think the problem was in my function one() definition 0_0 thx 31eee and adv12 You help me out :) – Mr Rubix Nov 19 '15 at 17:47

0 Answers0