troubleshooting Question

How to access a project methods from another project in same solution in C#

Avatar of Skale
Skale asked on
C#
6 Comments2 Solutions402 ViewsLast Modified:
Hello,

I have a two projects Project1 and Project 2 in same solution.

I'd like to use some functions from Project2 but i couldn't do it without defining a static field.
Is it normal? or How can i achieve this. Any help would be great to define it properly.

PS: I added Project2 to Project1's reference.

Project1's sample class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project1
{
   public class HelloFromProject1
    {

        public void SayHello()
        {

			// Calling method from another project here
			Project2.HelloFromProject2.SayHello();

        }


    }
}

This is Project2's sample class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project2
{
   public class HelloFromProject2
    {

        public void SayHello()
        {

            Console.WriteLine("Hello From Project 2");

        }


    }
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros