© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•12mo ago•
13 replies
PowerZox

Parameterless constructor in struct

public struct MyStruct
{
    public int id;
    static int count = 0;

    public MyStruct() //Not allowed?
    {
        id = count++;
    }
}
public struct MyStruct
{
    public int id;
    static int count = 0;

    public MyStruct() //Not allowed?
    {
        id = count++;
    }
}


Then public
MyStruct[] myStruct = new MyStruct[100];
MyStruct[] myStruct = new MyStruct[100];
should call the MyStruct() constructor 100 times.

How can I do this?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

EF parameterless constructor
C#CC# / help
2y ago
✅ what is a primary constructor? is it any similar to parameterless constructor?
C#CC# / help
16mo ago
❔ StructureMap.StructureMapException: StructureMap Exception Code: 207
C#CC# / help
3y ago