K
K
Kiril12212020-05-09 20:13:40
C++ / C#
Kiril1221, 2020-05-09 20:13:40

How to create a program launch counter inside the program itself (inside the class field)?

static class Program{
       static const Count=0;
        static void Main(){ 
                
// .....  что-то сложное
       }

What needs to be done, without files, so that the value of the count field changes every time the finished program is launched?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2020-05-09
@firedragon

Select any available storage. Cloud Stream
registry in file

C
Collin, 2020-05-12
@Collin

You can use a property that will save your value in Settings.settings
1. Create a parameter and value in Settings.settings
5eba43ef4737a482179842.png
2. Create a class, for convenience - static, import using yourNamespace.Properties;it so that you can use it Settings.Defaultand create a property there:

public static int Count
        {
            get
            {
                return (int)(Settings.Default["count"]);
            }
            set
            {
                Settings.Default["count"] = value;
                Settings.Default.Save();
            }
        }

now we can execute anywhere in the code.
YourStaticClass.Count = ++YourStaticClass.Count;
Important: do not use incrementing Count before InitializeComponent() if it is forms or WPF. Get an error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question