Calling an internal static function in an internal static class from Program class

raymac

Member
Joined
Jan 27, 2023
Messages
5
Programming Experience
5-10
Hi folks,
Could a learned member please advise me how I can access the 'Execute' function from this class (below), from my Main() code? If I make the class public & remove the static, I can do it, but this class must be accessible as is, or surely it wouldn't be a code example on Tobii's website? I must be doing something silly here!

The Class is as follows...

C#:
using System;
namespace Tobii.Research.CodeExamples
{
    internal static class EyeTrackingOperations_FindAllEyeTrackers
    {
        internal static EyeTrackerCollection Execute()
        {
            // <BeginExample>
            Console.WriteLine("\nSearching for all eye trackers");
            EyeTrackerCollection eyeTrackers = EyeTrackingOperations.FindAllEyeTrackers();
            foreach (IEyeTracker eyeTracker in eyeTrackers)
            {
                Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}", eyeTracker.Address, eyeTracker.DeviceName, eyeTracker.Model, eyeTracker.SerialNumber, eyeTracker.FirmwareVersion, eyeTracker.RuntimeVersion);
            }
            // <EndExample>
            return eyeTrackers;
        }
    }
}

and I am using the following code to try and call the Execute() function...

C#:
using System;
using Tobii.Research.CodeExamples;

namespace ET5
{
    class Program
    {
        static void Main(string[] args)
        {
            CallEyeTrackerManager et = new CallEyeTrackerManager();
            et.Execute();
        }
    }
}

Thanks again :)
 
You can only access it if you are compiling your code in the same assembly.

Not all sample code are created equal. Some companies defer writing samples to interns.

In general, though, sample code is meant to be just read so that concepts can be picked. They are usually not meant for production use.
 
Last edited:
If they're in the same project:

C#:
        static void Main(string[] args)
        {
            CallEyeTrackerManager et = new CallEyeTrackerManager();
            EyeTrackingOperations_FindAllEyeTrackers.Execute(); //and needs this at the top of the file:   using Tobii.Research.CodeExamples;
        }

If they're in different projects:

you can't

----

Avoid using static - it will teach you nothing good
 
Back
Top Bottom