Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
3,191 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Is possible to use the same void between multiple forms in the same project?
If it possible, how is it done?
You can see for example the answer from RoninB in this thread :
One option is using a thread safe singleton
public sealed class AppOperations
{
private static readonly Lazy<AppOperations> Lazy =
new(() => new AppOperations());
private const int _max = 5;
public static AppOperations Instance => Lazy.Value;
public int Index { get; set; }
public void Increment()
{
if (Index + 1 < _max)
{
Index++;
}
else
{
Index = 0;
}
}
public void Decrement()
{
Index--;
if (Index < 0)
{
Index = _max - 1;
}
}
}
Usage in one form
AppOperations.Instance.Increment();
In another form var value = AppOperations.Instance.Index;