Can the user structure be the entry point (main entry) in the program?

This is a rhetorical question, because as far as the IDE shows me, this is possible (that is, it suffices to create the Main method, and everything will go bang away).

But another question arises from this - what is it fraught with and is it considered a bad ton !?

    1 answer 1

    The entry point to a program in C # is the Main method. This method must be static. Static elements of a class or structure are independent program units, do not require an instance to call and, in fact, use the name of the class or structure in which they are declared only to extend their own name and ensure its uniqueness. Static members are not inherited, they cannot be abstract or virtual, you can even write completely in a procedural style, using only static classes and their elements.

    The structure is essentially a class, but with disabilities, in which at the language level some principles of OOP are forbidden (inheritance from other classes or structures is prohibited, but the implementation of interfaces is allowed, the rest is the consequence). Well, yes, the structures are related to ValueType, which imposes some more restrictions, but at the same time, makes it impossible for classes to be available. However, in terms of static elements, the structure does not differ from the classes, except that the structure itself cannot be static.

    Therefore, from the point of view of the CLR, there is no difference to which the Main method will be attached, and there will be no consequences from such a replacement. Another question. how you will use this class or structure in the future, but this is really another question.

    • "The structure is essentially a class, but with disabilities, in which it is forbidden to use the basic principles of OOP at the language level (fields must be open" why should the fields have to be open? Can it mean not initializing? - CSharpUser
    • @CSharpUser yes, you are right, I mixed it up with something else. There may well be private fields, only then they must be initialized in the constructor. in the case of open fields, you can do without a constructor at all - rdorn
    • the fields are initialized in the default constructor, which cannot be modified (in user structures), and the access modifier does not matter (be ticked as Private / Protected / Public), for the default structures of the user structures are CSharpUser
    • @CSharpUser for sure, thanks for making you refresh your knowledge, and for an interesting question =) removed the extra from the answer - rdorn
    • I can’t send you a message for some reason, apparently closed the opportunity. Mark your post as reply. - CSharpUser