Use methods of one file in another file

c#, namespaces, oop

Solution

You have to create an instance of the second class. than you can call methods of it. Or you make the methods in the second class public.

public class Class1
{
   public void Function()
   { ... }
}

public class Class2
{
   public void AnotherFunction()
   {
      Class1 class1 = new Class1();
      class1.Function();
   }
}

Ok. Let's say that you have 2 projects in your solution "Project1" and "Project2". In Project1 you have a Class called Project1Class which contains a method "Foo" you want to use in Project2. First you have to add a Referenze to Project1 in Project2 (Right-Click References->Add Reference -> Solution->Project1). In Project2 you have a class Project2Class which contains a method "AccessProject1Class". The code of this class looks like:

using Project1;

namespace Project2
{
    public class Project2Class
    {
        public void AccessProject1Class()
        {
            Project1Class project1Class = new Project1Class();
            project1Class.Foo();
        }
    }
}

Problem

I am a beginner in C#. I have written some functions in File1.xaml.cs I have another tester file Test.xaml.cs in which I need to test the functions I wrote in File1.xaml.cs. How can I do that ? Both the files are under the same namespace.

Original source